In PHP, file_exists () is used to determine whether the Chinese file name is invalid,
This article describes how to use file_exists () in PHP to determine invalid Chinese file names. Share it with you 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. However, when file_exists is used, if your file name or path is Chinese, it is invalid in uft8 encoding documents. This article will solve this problem. Let's take a look at it.
Definition and usage:
The file_exists () function checks whether a file or directory exists.
If the specified file or directory exists, true is returned; otherwise, false is returned.
Example 1
Copy codeThe Code is as follows: <? Php
Echo file_exists ("test.txt ");
?>
Output:
1
Example 2
Copy codeThe Code is as follows: Export realname+'chinese.txt ';
If (file_exists ($ realname )){
// Never get in here
}
Else
{
Echo 'www .jb51.net reminding you that the file does not exist ';
}
The output result is www.jb51.net, reminding you that the file does not exist.
However, I was surprised that the PHP file exists, and the PHP file is not in the same directory as the Chinese TXT file. So there is no problem in writing this file. When I think about it, will it be a Chinese problem? I will convert the encoding.
Solution:
Copy codeThe Code is as follows: Export realname+'chinese.txt ';
If (file_exists (iconv ('utf-8', 'gb2312', $ realname ))){
// This will support
}
The result shows 1. The problem is solved.
In addition, we also need to remind you that it is best not to use Chinese names in php, such as apache, linux, and php, which do not support Chinese very well, so you should try your best to use English.
I hope this article will help you with PHP programming.