file_exists - Check whether the file or directory exists; the syntax is as follows
file_exists ( $filename )
The parameter filename is the path of the file or directory. Returns TRUE if the file or directory specified by filename exists, FALSE otherwise.
But this function cannot return the correct value for Chinese file names or folder names when the web page uses UTF8 encoding, and always returns false. After testing, we came up with a solution and analyzed that the reason for this situation should be that PHP cannot judge correctly due to different encodings.
The following code cannot return the correct value, regardless of whether the file is present or not:
<?php; $file="/attachment/21/0/中文.rar"; $newfile = dirname(FILE).$file; echo file_exists($newfile); ?>
After testing, a sentence is added to convert UTF8 encoding to GB2312 encoding. , you can make a correct judgment:
<?php $file="/attachment/21/0/中文.rar"; $newfile = dirname(FILE).$file; $file=iconv('UTF-8','GB2312',$file); echo file_exists($newfile); ?>
The above is the detailed content of Detailed examples of solutions to the problem that the file_exists function in PHP does not support Chinese names. For more information, please follow other related articles on the PHP Chinese website!