Home > Article > Backend Development > The solution to the invalid determination of Chinese file names by file_exists() in PHP, _PHP tutorial
The example in this article describes the solution to the problem that file_exists() in PHP determines that Chinese file names are invalid. Share it with everyone for your reference. The specific method is as follows:
To determine whether a file exists in PHP, we will use the file_exists function or the is_file function, but when using file_exists, if your file name or path is in Chinese, it will be invalid when encoding the document in uft8. This article will solve this problem, let’s take a look below.
Definition and usage:
The file_exists() function checks whether a file or directory exists.
Returns true if the specified file or directory exists, false otherwise.
Example 1
if(file_exists($realname)) {
// You can never get in here
}
else
{
echo 'www.jb51.net reminds you that the file does not exist';
}
Solution:
The result shows 1, the problem is solved
In addition, I also need to remind everyone that it is best not to use Chinese names in PHP. Apache, Linux, and PHP do not support Chinese very well, so everyone should try to use English.
I hope this article will be helpful to everyone’s PHP programming design.