我有下面的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);
似乎什么都不起作用,我一直得到错误的文本我需要得到文本来检查文件是否存在。。。
确保文件系统的编码与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
}