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

184
Views
Php saves uploaded files with wrong encoding on linux server

I have a classic php script for saving tmp files:

$uploads_dir = "scans";
var_dump( $_FILES );
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];

        rename($tmp_name, urldecode("/var/www/html/$uploads_dir/$name") );
    }
}
echo urldecode("/var/www/html/$uploads_dir/$name");

However, the file 'фавикон.png' gets saved as 'фавикон.png'. Please help me out what to do with encoding.

Thank you

EDIT:

Got it working with iconv function. However, for some weird reason it had to be encoded into windows format.

The resulting code:

if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
    $name = $_FILES["pictures"]["name"][$key];
    $name =iconv('UTF-8','windows-1251',  $name);
    copy($tmp_name, "/var/www/html/$uploads_dir/$name");
}
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You might need the following setlocale(LC_ALL, 'ru_RU.utf8')

over 4 years ago · Santiago Trujillo Report

0

try to put this line on the top of the script:

header('Content-Type: text/html; charset=utf-8');
over 4 years ago · Santiago Trujillo Report

0

Have you try to use utf8_decode:

utf8_decode($name);

I suggest that you change the name of the file, there are very good reasons to do this. Check this post for more details: https://stackoverflow.com/a/17866898/1016425

over 4 years ago · Santiago Trujillo 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!