file_exists函数在PHP中不支持中文

2023-06-08  本文已影响0人  风度翩翩的程序猿
要解决file_exists函数在PHP中不支持中文的问题,可以采用以下2种方法:
$fileName = '中文文件名.txt';
$fileName = iconv('UTF-8', 'GBK', $fileName);
if (file_exists($fileName)) {
    //文件存在
} else {
    //文件不存在
}



2、
$fileName = '中文文件名.txt';
$fileName = mb_convert_encoding($fileName, 'GBK', 'UTF-8');
if (file_exists($fileName)) {
    //文件存在
} else {
    //文件不存在
}

上一篇 下一篇

猜你喜欢

热点阅读