_php Skills of PHP file_exists

Source: Internet
Author: User
Problem

The company has a framework is based on Smarty write, I am responsible for the upgrade of PHP, maintenance personnel to the new environment, after the test staff to find me to make frequent error (Error: Hint can not find the file).
I traced the code and it was the smarty of the local newspaper.

Error: Here the file does not exist.
Thinking Process:
1, I thought it was not the file in the program, the results found that the file is there, that is how the matter?
2, then I guess the PHP kernel is not a problem, I have PHP related to the kernel file read again, did not find the problem. As a result I said the whole process to the project manager. --things didn't work out, so let it go. The upgrade was delayed first.
Today again found this problem, my first reaction is that the PHP version is not upgraded, found no. -then it's OK to set the entire directory to 777 (chmod 777-r directory). I think it is file_exists () method problem.
Therefore, I have carried out the related debugging and the experiment.

Debugging process
Debug code:

Directory:

Observe the permissions: test does not have any permissions on www, while the execution file index.php has read and write execution rights, including files Test.txt have read and write permissions.

Run Result:

The execution permissions of the directory affect file_exists ()
1, give test one of the largest permissions--755


Now that you are successful, the file_exists () function is restricted by directory permissions.
So what kind of directory permissions affect File_exists ()?
I did a few experiments:
1, the file of any superior directory, only write permission times file does not exist;
2, the file of any superior directory, only read the right to report the file does not exist;
3, and when all the superior directory has executive authority, the newspaper file is there, everything is normal.
As a result, the file_exists () is recursive to determine whether the file exists, and that each directory has execute permissions.

Modifying the file path to a relative path results in the same result.

Summary

It is not mentioned in the PHP manual that the file_exists will be affected by the execution permissions of the directory. This article tells the developers who also have this problem. This is the only ring.

Additional Information

Thank you for leaving a message, very useful. After everyone's opinion, I checked the manual, indeed, if the directory does not execute permissions, the PHP-FPM application process can not go to the directory to search for files, of course, that the file does not exist (actually think that no executable directory is not exist).
The contents of the manual, you can consider together, mainly the executive authority. Here is not to dwell on the right to read and write (generally very well understood).

In the clear manual, there is a clear indication of the permissions to execute the directory. Permission to execute a directory is to have the right to be searched.

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.