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

125
Views
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
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!