An invalid solution for parsing php file_exists

Source: Internet
Author: User

Method 1:According to the official manual, if the safe mode settings of the php tutorial are too harsh, the following situation may occur: although the file actually exists, it is also reported that the file does not exist.

Because the php. ini cannot be operated. When ini_set () is used, the safe mode cannot be disabled. We have to go back and find a more reliable and secure detection method to check whether a file exists. We can implement this by using $ _ server ['document _ root. $ _ Server ['document _ root'] returns the root directory of the website. the last sub-directory of the website does not contain the directory symbol "/", for example:
D:/www/htdocs
With the root directory and the path of the file to be checked, we will get an absolute path, and php will be able to smoothly use the file_exists () function for detection. In 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 ";
In this way, the code execution is very credible and there will be no unexpected results.
The preceding method is also applicable to the related Detection Functions of directories (is_dir () or files (is_file (). It can detect the existence of secure directories or files.

Finally, by the way, this type of files protected by special php settings do not need to add the $ _ server ['document _ root'] path when referencing (include and require) because, according to the php instructions, they are allowed to be referenced.

Method 2:The reason is that files are moved back and forth between windows and linux. In linux, the access permissions of files and directories are changed, and the outgoing files have no access permissions except the owner. Use chmod-r 755 xxx/* to solve the problem.

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.