Reading client side text file using Javascript -


i want read file (on client side) , content in array. 1 file. have following , doesn't work. 'query_list' textarea want display content of 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 go it? want loop on array , run sql queries.

if want read files on client using html5's filereader, must use firefox, chrome or ie 10+. if true, following example reads text file on client.

your example attempts use fopen have never heard of (on client)

http://jsfiddle.net/k3j48zmt/

   document.getelementbyid('file').addeventlistener('change', readfile, false);     function readfile (evt) {        var files = evt.target.files;        var file = files[0];                   var reader = new filereader();        reader.onload = function(event) {          console.log(event.target.result);                    }        reader.readastext(file)     } 

for ie<10 support need using activex object ado.stream scripting.filesystemobject http://msdn.microsoft.com/en-us/library/2z9ffy99(v=vs.85).aspx you'll run security problem. if run ie allowing activex objects (for website), should work.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -