我有以下PHP脚本
<?php
header('Content-Type: text/html; charset=utf-8');
$file = "//192.168.10.206/wwwroot/SABIS CORPORATE/PrepList/Documents/41/1516 Level I Arabic Basic Questions and Answers T1 الأسلوب الخبري.pdf";
echo $file;
?>
结果总是
PS C:\Users\aaoun> php -q c:\Users\aaoun\Desktop\Test-AAA.php
//192.168.10.206/wwwroot/SABIS CORPORATE/PrepList/Documents/41/1516 Level I Arabic Basic Questions and Answers T1 ╪د┘╪ث
╪│┘┘ê╪ذ ╪د┘╪«╪ذ╪▒┘è.pdf PS C:\Users\aaoun>
我尝试了UT8编码
iconv("unicode", "utf-8", $file);
iconv("Latin1_General_CI_AS","utf-8",$file);
iconv("Arabic_CI_AS","utf-8",$file);
base64_encode($file);
utf8_encode($file);
base64_decode($file);
utf8_decode($file);
iconv('WINDOWS-1256', 'UTF-8', $file);
iconv('cp1256', 'UTF-8', $file);
似乎什么都没有用,我总是搞错了,我需要让文本检查文件是否存在.
发布于 2015-12-14 04:00:06
确保文件系统的编码与PHP代码中包含文件名的字符串的编码相同。
否则,您将测试是否存在错误的文件。
例如,如果您的文件系统不支持UTF-8,但是文件名是以UTF-8编码的.在使用Windows时,值得注意的是,Windows文件系统(FAT、FAT32、NTFS)不知道UTF-8。您可以将文件名转换为UTF-16,类似于
$newName = mb_convert_encoding('your file path', 'UTF-16', 'UTF-8');
如果这不起作用,您可以使用urlencode
。从urlencode返回的所有字符在文件名(NTFS/HFS/UNIX)中都是有效的。
$newName = urlencode($file);
尝试使用此代码来了解该文件是否存在:
if (file_exists('your file path')) {
//file exists;
}
else
{
//Does not exist
}
https://stackoverflow.com/questions/34266402
复制相似问题