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

127
Vistas
php csv file with special char through Ajax

In my project I take the file from an html file input (in a modal), then I pass it with ajax to php and with the $_FILE super variable I get his content:

The modal

<form id="form_admin_panel_import" enctype="multipart/form-data" method="post">
  <input type="file" class="form-control" name="usersFile" id="usersFile">
  <button type="submit" class="btn btn-primary" id="buttonAction">Import
  </button>                                                      
</form>

Js and Ajax

$( "#form_admin_panel_import" ).submit(function( event ) {
    event.preventDefault();
    var fd = new FormData(this);
    $.ajax({
        url: (URL + "managementUsers/importUsers"),
        type: "POST",
        data: fd ,
        processData: false,
        contentType: false,
        success: function (result) {
            console.log(result);
        }
    });
});

php

if ( 0 < $_FILES['usersFile']['error'] ) {
  echo 'Error: ' . $_FILES['usersFile']['error'] . '<br>';
}
else {
  if (($handle = fopen($_FILES['usersFile']['tmp_name'], "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
      $firstName = $data[0]; 
    }
  }

The problem is that when I have special chars in the csv file the php receives a ? char and I cannot get back to the original char. I think that I have to use an UTF8 Header but I don't know where...

about 4 years ago · Juan Pablo Isaza
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