0

I'm trying to rename a file,

That file generated by unizp a zip file, but the file have a strange character

Lieferungen und R�cklieferungen_RvP_2019_02_04.csv

we can't have control over that character becoz we getting zip file from 3rd party.

that symbol is ü but when unzip using php code it shows that strange symbol.

I tried using this code

$files = glob("/xxxxmyfullpath/unzipped/*.csv");
echo $numfiles = count($files);

if ($numfiles == 1) {
  // Rename it
  echo $files[0];
  rename($files[0], "testing.csv");
}

but the glob doesn't seems identify the file.

anyone know how to remove that unrecognized symbol from file name please

Suneth Kalhara
  • 1,116
  • 4
  • 16
  • 40
  • 1
    Sounds like your charset isn't set to the same as that of the file. I recommend you try to set your PHP header to utf8, `header('Content-Type: text/html; charset=utf-8');` at the top of your file. – Qirel Feb 13 '19 at 07:10
  • i'll try that but we unzip using shell command echo shell_exec('7z x "'.$zipfile.'" -o"'.$extractfilepath.'" -passwordhere'); – Suneth Kalhara Feb 13 '19 at 07:11
  • 1
    You might also need `utf8_encode()` if you cannot control the original source of the name. – Qirel Feb 13 '19 at 07:14

1 Answers1

0

Filename is coded probably Windows-1252, Western-Europe, but your terminal probably uses UTF-8. � = ü = ü Latin small letter u with diaeresis. If your $numfiles is greater than 1, your rename code won't run at all. If the name of your extracted file contains illegal characters, it won't "glob" at all. Before you unzip your archive, you have to switch to a legacy codepage. Try: setlocale(LC_ALL, 'C'); and then, try to run your code.