In general, PHP often uses file_exists () to determine whether a file or folder exists, returns True if it exists, or returns false. However, the function does not return the correct value for the Chinese file name or folder name when the Web page uses UTF8 encoding, always returns false. After testing the solution, the analysis of the cause of this situation should be different coding caused by PHP can not be correctly judged.
The following code is code that is not able to return the correct value, regardless of whether the file is not returned:
<?php;
$file = "/attachment/21/0/Chinese. rar";
$newfile = DirName (__file__). $file;
echo file_exists ($newfile);
? >
After testing, add a sentence to convert UTF8 encoding to GB2312 encoded statements, you can correctly judge:
<?php
$file = "/attachment/21/0/Chinese. rar";
$newfile = DirName (__file__). $file;
$file =iconv (' UTF-8 ', ' GB2312 ', $file);
echo file_exists ($newfile);
? >