Summary of problems encountered in the use of file_exists in PHP, and summary of file_exists. Summary of problems encountered in file_exists usage in PHP. I have found a problem in file_exists summary. I will share it with you today. I will describe the entire process. Problem: The company has a summary of the problems encountered by file_exists in PHP.
Introduction
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 upgrades. after the maintenance personnel bring up the new environment, the tester asks me to report 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.
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.
If this article is helpful to you or helps you solve such problems, please recommend that you give your friends a stronger motivation for writing.
Articles you may be interested in:
- Php file_exists: checks whether a file or directory exists.
- Differences between file_exists and is_file and is_dir in PHP
- An invalid solution for parsing php file_exists
- Why is_file in PHP cannot replace file_exists
- In PHP, the file_exists function does not support Chinese names.
- In PHP, file_exists () is used to determine whether the Chinese file name is invalid.
- In PHP, how does one determine whether an object exists using is_file or file_exists?
- How to use the file_exists function in php
Workshop introduction I found a problem and I will share it with you today. I will describe the entire process. Question: The company has a box...