PHP file_exists Invalid workaround _php Tutorial

Source: Internet
Author: User
Method 1: According to the official manual, if the Safe mode setting of the PHP tutorial is too harsh, this situation occurs: Even though the file is real, it is mistakenly reported that the file does not exist.
Because the server side of the php.ini we can not manipulate, when using Ini_set () also shut down the safe mode, we only go back and second, find a more reliable and safe detection method to detect the existence of files. We can do that with $_server[' document_root '. $_server[' Document_root ' returns the root directory of the Web site, and the last subdirectory of the directory does not contain the directory glyph "/", such as:

D:/www/htdocs
With the root directory, along with the path of the file that needs to be detected, we will get an absolute path, and PHP will be able to use the file_exists () function to detect it. The above code we only need to change the first behavior (note that we added the symbol "/" before config.php):

$file =$_server[' Document_root ']. " /config.php ";
Thus, the execution of the code is credible and does not result in unexpected results.

The above method is also applicable to the related detection function of the directory (Is_dir ()) or the file (Is_file ()), which can detect the existence of the secured directory or file.

Finally, incidentally: this type of file that is protected by PHP special settings does not have to be prefixed with the $_server[' document_root ' path when referencing (include and require) because, according to the PHP documentation, they are allowed to be referenced.

Method 2: I'm in the situation because the files move back and forth between Windows and Linux. Access to files and directories under Linux has been changed, resulting in no access to files other than the owner. Using the Chmod-r 755 xxx/* solves the problem.

http://www.bkjia.com/PHPjc/632318.html www.bkjia.com true http://www.bkjia.com/PHPjc/632318.html techarticle Method 1: According to the official manual, if the Safe mode setting of the PHP tutorial is too harsh, this situation occurs: Even though the file is real, it is mistakenly reported that the file does not exist. ...

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