You can do this using the Filereader API. In the example below, you can save the contents of the selected TXT file to input type=file
in the variable texto
:
<input type="file" id="files" name="files[]" />
<script>
function lerArquivoTxt(evt){
var texto = "";
var files = evt.target.files;
for (var i = 0, f; f = files[i]; i++){
var reader = new FileReader();
reader.onload = function(event){
var conteudo = event.target.result;
var linhas = conteudo.split('\n');
for(x=0;x<linhas.length;x++){
texto += linhas[x];
}
alert(texto);
};
reader.readAsText(f);
}
}
document.getElementById('files').addEventListener('change', lerArquivoTxt, false);
</script>