Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda