Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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...

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda