PHP file_exists () to determine the invalid Chinese file name resolution, _php tutorial

Source: Internet
Author: User
Tags php programming

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. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.