Method 1: According to the official manual, if the PHP tutorial's Safe Mode settings are too harsh, there is a scenario where the file does not exist, even if it is false.
Because the server side of the php.ini we can not manipulate, when using Ini_set () also can not close the Safe Mode mode, we have to return to the second, find a more reliable, safe detection methods to detect the existence of files. We can use $_server[' document_root ' to realize it. $_server[' Document_root ' returns the root 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, plus the path of the file that needs to be detected, we'll get an absolute path, and PHP will be able to use the file_exists () function to detect it. The above code we just need to change the first behavior (note that we added the symbol "/" before config.php):
$file =$_server[' document_root ']. " /config.php ";
as a result, the execution of the code is trustworthy and does not appear as expected.
The above methods also apply to the relevant detection functions of the directory (Is_dir ()) or file (Is_file ()), which detects whether the directory or file being secured is present.
Finally, incidentally: this type of file protected by the PHP special settings does not have to be added with the $_server[' document_root ' path when referencing (include and require) because, according to PHP documentation, they are allowed to be referenced.
Method 2: My situation is because the file is moving back and forth between Windows and Linux. The Linux file and directory access permissions are changed, resulting in files other than the owner has no access rights. Using Chmod-r 755 xxx/* solves the problem.