Jump to content

Javascript File Reader


sstangle73

Recommended Posts

I may just not be understanding the file reader api, but

 

When I try to run:

 

   

    for (var i = 0, f1, f2; f1 = files[sorted_index[i]], f2 = files[sorted_index[i+1]]; i=i+2) {
	var file_one;
	var file_two;

	if(f1.size < f2.size){
		file_one = f1;
		file_two = f2;
	} else {
		file_one = f2;
		file_two = f1;
	}
      
	var file_one_contents;
	var file_two_contents;


      var reader = new FileReader();
      reader.readAsText(file_one);
  reader.onload = readSuccess;
  
  function readSuccess(evt){
	file_one_contents = evt.target.result;
  }
  var reader = new FileReader();
	reader.readAsText(file_two);
	reader.onload = readSuccess2;
  
  function readSuccess2(evt2){
	file_two_contents = evt2.target.result;
  }

	console.log(file_one_contents);
	console.log(file_two_contents);

 

The console log only contains *undefined* in it.

The goal of the script it two read in two CSVs and take the data from the pair of files and do some computations.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/266453-javascript-file-reader/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.