The file_exists function in PHP does not support Chinese name resolution, _php tutorial

Source: Internet
Author: User

The file_exists function in PHP does not support Chinese name resolution,


In general, PHP often uses file_exists () to determine whether a file or folder exists, and returns true if it exists, otherwise false. However, this function does not return the correct value for the Chinese file name or the folder name if the Web page uses UTF8 encoding, and always returns false. After testing, the solution is obtained, and the reason for this is that PHP cannot be judged correctly due to different coding.

The following code is not able to return the correct value of the code, regardless of whether the file is returned in the not:

<?php; $file = "/attachment/21/0/Chinese. rar"; $newfile = DirName (__file__). $file; Echo file_exists ($newfile);? >

After testing, added a sentence to convert the UTF8 encoding into a GB2312 encoded statement, you can correctly judge:

<?php$file= "/attachment/21/0/Chinese. rar"; $newfile = DirName (__file__). $file; $file =iconv (' UTF-8 ', ' GB2312 ', $file); echo file_exists ($newfile);? >



http://www.bkjia.com/PHPjc/851352.html www.bkjia.com true http://www.bkjia.com/PHPjc/851352.html techarticle php file_exists function does not support the solution of Chinese name, in general, PHP often use file_exists () to determine whether a file or folder exists, if present, return true, otherwise ...

  • Related Article

    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.