PHP talks about file_exists and file_exists.

Source: Internet
Author: User

PHP talks about file_exists and file_exists.
Introduction I found a problem and I will share it with you today. I will describe the entire process. The problematic company has a framework written based on smarty. I am responsible for php upgrades. 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 whether the php version was upgraded or not. -- 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.

Code for debugging:

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. Grant test the maximum permission -- 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.

 

 

The summary is 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. The additional information is very useful for your remarks. 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.

If this article is helpful to you or helps you solve such problems, please recommend it so that you have a stronger motivation for writing.

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.