PHP file_exists () to determine the invalid Chinese file name resolution,
In this paper, we describe the resolution of file_exists () in PHP to determine the invalid Chinese file name. Share to everyone for your reference. Here's how:
In PHP, we use the file_exists function or the Is_file function to determine whether a file exists, but when you use file_exists, it is not valid if your file name or path is Chinese in the UFT8 encoded document. This article is to solve this problem, let's look at it together.
Definition and Usage:
The file_exists () function checks whether a file or directory exists.
Returns true if the specified file or directory exists, otherwise false.
Example 1
Copy the Code code as follows: <?php
Echo file_exists ("test.txt");
?>
Output:
1
Example 2
Copy the Code code as follows: $realname = ' Chinese. txt ';
if (file_exists ($realname)) {
It's 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 remind you that the file does not exist.
But I'm surprised. The file is present and the path is not the problem PHP files are in the same directory as Chinese. txt so it is no problem to think about whether it is Chinese, I convert the code
Solution:
Copy the Code code as follows: $realname = ' Chinese. txt ';
if (File_exists (Iconv (' UTF-8 ', ' GB2312 ', $realname))) {
So that we can support the
}
The results show that 1, the problem solved
Also need to remind you, in PHP is best not to use Chinese names, such as apache,linux,php these Chinese support is not very good, so we try to use English.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/910601.html www.bkjia.com true http://www.bkjia.com/PHPjc/910601.html techarticle php file_exists () to determine the invalid Chinese file name resolution method, this article describes the PHP file_exists () to determine the invalid Chinese file name resolution method. Share to everyone for your reference. ...