doutou3725 2019-02-13 07:08
浏览 145

PHP重命名具有无法识别字符的文件

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

  • 写回答

1条回答 默认 最新

  • dsmupo6631 2019-02-15 00:37
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波