The file_exists function in PHP cannot detect a solution that contains Chinese filenames

Source: Internet
Author: User
PHP generally uses file_exists () to determine whether a file or folder exists, and if the file or folder exists, returns True, False if it does not exist. Today, when implementing the file download function, it is found that the function cannot detect whether a file containing Chinese is present, and always returns false, in the case of a Web page using UTF8 encoding. The modification was long after the discovery because the full path was not encoded, and simply transcoding the file name was not enough.

The following code cannot detect whether a file containing Chinese is present, regardless of whether the file returns false:

 
 
  

Just to transcode the file name is not, this is the case I encountered, need to "path + file name" together to Transcode to

 
  

In fact, as long as the file path and file name from UTF8 encoding to GB2312 encoding, improved can be accurately judged:

 
    


The above describes the PHP file_exists function can not detect the file name containing the Chinese version of the solution, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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