Php learning path: potholes file_exists-php tutorial

Source: Internet
Author: User
Php learning path: Introduction to file_exists

I found a problem and I will share it with you today. I will describe the entire process.

Problem

The company has a framework written based on smarty. I am responsible for php upgrade. after the maintenance personnel bring up the new environment, the tester asks me for frequent errors (errors: the file cannot be found ).

I tracked the code and reported an error in the place of smarty.

  

Error: The file does not exist.

Thinking process:

1. I thought this file was not found in the program. I found that the file exists. what is the problem?

2. then I guess if there is a problem with the php kernel. I read the relevant php kernel file and I have not found any problems. As a result, I told the project manager about the entire process .?? The problem has not been solved, so the problem will not be solved first. The upgrade is delayed first.

Today I found this problem again. My first reaction was that the php version was upgraded, but I didn't find it .?? Later, set the entire directory to 777 and it will be okay (chmod 777-R directory ). I want to see if it is a problem with the file_exists () method.

Therefore, I conducted relevant debugging and experiments.

Debugging process

Debug code:

Directory:

Observe the permissions: testhas no permissions for www. the execution file index.php has the read and write permissions, and the execution file test.txt has the read and write permissions.

Running result:

The execution permission of the directory affects file_exists ()

1. what is the maximum permission for test ?? 755

If the operation succeeds, the file_exists () function is restricted by the Directory permission.

What directory permissions will affect file_exists?

I have done several experiments:

1. any parent directory of the file. the file does not exist when the write permission is enabled;

2. in any parent directory of the file, the file does not exist if the read permission is limited;

3. when all the parent directories have the execution permission, the system reports that the file exists and everything works normally.

The result indicates that when determining whether a file exists, file_exists () recursively determines whether each directory has the execution permission.

Change the file path to a relative path to get the same result.

Summary

As not mentioned in the php Manual, file_exists is affected by directory execution permissions. This article tells developers who have problems in this regard. This is the only rule.

Additional information

Thank you for your remarks. they are very useful. After your comments, I checked the manual again. Indeed, if the directory does not have the execution permission, the php-fpm application process will not be able to search for files under this directory, of course, the file does not exist (actually there is no executable directory ).

The content of the manual, which can be considered together, is mainly the execution permission. I will not discuss the read and write permissions in detail here (it is generally easy to understand ).

Clearly, the manual provides clear instructions on directory execution permissions. The execution permission on the directory is 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.