Reading client side text file using Javascript

I want to read a file (on the client side) and get the content in an array. It will be just one file. I have the following and it doesn't work. 'query_list' is a textarea where I want to display the content of the file.

<input type="file" id="file" name="file" enctype="multipart/form-data"/>

    <script>
       document.getElementById('file').addEventListener('change', readFile, false);

       function readFile (evt) {
           var files = evt.target.files;
           var file = files[0];

          var fh = fopen(file, 0);
          var str = "";
          document.getElementById('query_list').textContent = str;
          if(fh!=-1) {
             length = flength(fh);        
             str = fread(fh, length);     
             fclose(fh);                   
           } 
           document.getElementById('query_list').textContent = str;
        }
      </script>

How should I go about it? Eventually I want to loop over the array and run some SQL queries.

30
задан Jean-François Corbett 8 September 2017 в 11:07
поделиться