Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Javascript readfile with filename

I want read file with filename But function gives me error

    var data = "class.php"
    var reader = new FileReader();
    var result  = reader.readAsText(data);
    console.log(result);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

JavaScript can read local files using the FileReader() but not automatically, meaning that the user has to pass the file (or a list of files) to the script with an html <input type="file">.

After that, JavaScript will be able to process the file (or list of files).

JavaScript cannot access the filesystem of your computer for security reasons without the user input.

So, if you want to it, you will need to create an html document having that html input and then read the file content.

Then, you can handle the file in the click event handler like so:

var fr = new FileReader();
fr.onload = function(e) {
   const text = e.target.result;
};
fr.readAsText(file);

readAsText is asynchronous, you will need to use the onload callback to see the result.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!