This article illustrates the solution of file_exists () in PHP to determine the Chinese filename is invalid. Share to everyone for your reference. The specific methods are as follows:
PHP to determine whether the existence of the file we will use the File_exists function or Is_file function, but when using file_exists if your file name or path is Chinese in the UFT8 encoding document is invalid. This article is to solve this problem, let's take a look at the following.
Definition and Usage:
the file_exists () function checks whether a file or directory exists.
Returns true if the specified file or directory exists, or FALSE.
Example 1
Copy Code code as follows:
<?php
Echo file_exists ("test.txt");
?>
Output:
1
Example 2
Copy Code code as follows:
$realname = ' Chinese. txt ';
if (file_exists ($realname)) {
Never going to get in here.
}
Else
{
Echo ' Www.jb51.net reminds you that the file does not exist ';
}
The output is www.jb51.net to remind you that the file doesn't exist.
But I'm surprised. File is there, and the path is no problem php file with Chinese. txt in the same directory so write is no problem, think about it is not a Chinese problem, I have to convert the code
Solution:
Copy Code code as follows:
$realname = ' Chinese. txt ';
if (File_exists (Iconv (' UTF-8 ', ' GB2312 ', $realname))) {
So that we can support the
}
The results show 1, the problem is solved
In addition, we also need to remind you that in PHP, it is best not to use Chinese names, such as apache,linux,php of Chinese support is not good, so we try to use English.
I hope this article will help you with your PHP program design.