Home  >  Article  >  Backend Development  >  Invalid solution to parsing php file_exists_PHP tutorial

Invalid solution to parsing php file_exists_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:02:33968browse

Method 1: According to the official manual, if the safe mode-related settings of the PHP tutorial are too harsh, a situation will arise: even though the file actually exists, it will be falsely reported, thinking that the file Doesn't exist.

Since we cannot control the php.ini on the server side, and the safe mode cannot be turned off when using ini_set(), we can only resort to the next best thing and find a more reliable and safe detection method to detect whether the file exists. We can achieve this with the help of $_server['document_root']. $_server['document_root'] returns the root directory of the website. The last subdirectory of the directory does not contain the directory identifier "/", such as:
d:/www/htdocs
With the root directory and the path of the file that needs to be detected, we will get an absolute path, and PHP can successfully use the file_exists() function to detect it. We only need to change the first line of the above code (note that we added the symbol "/" before config.php):
$file=$_server['document_root']."/config.php" ;
In this way, the execution of the code is very reliable and there will be no unexpected results.
The above method is also applicable to the related detection function of directory (is_dir()) or file (is_file()), which can detect whether the directory or file that is protected by security exists.

Finally, by the way: this type of files protected by PHP special settings do not need to be referenced (include and require) with the $_server['document_root'] path, because, according to the PHP documentation, they are Citations are allowed.

Method 2: In my case, the file was moved back and forth between windows and linux. As a result, the access permissions of files and directories under Linux are changed, resulting in no one except the owner of the file having access permissions. Using chmod -r 755 xxx/* solved the problem.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327906.htmlTechArticleMethod 1: According to the official manual, if the safe mode related settings of the php tutorial are too harsh, this will happen. Situation: Although the file actually exists, it is falsely reported as not existing. ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn