title: Reading client side text file using Javascript
body: <p>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. <code>'query_list'</code> is a textarea where I want to display the content of the file.   </p>
  
  <pre><code>&lt;input type="file" id="file" name="file" enctype="multipart/form-data"/&gt;
  
      &lt;script&gt;
         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;
          }
        &lt;/script&gt;
  </code></pre>
  
  <p>How should I go about it? Eventually I want to loop over the array and run some SQL queries.</p>