PHP talk about the file_exists of the pit father, file_exists_php tutorial

Source: Internet
Author: User

PHP talk about the pit Father File_exists, file_exists


Introduction I found a problem to share with you today. I'll describe the whole process.  The problem company has a framework is based on Smarty write, I am responsible for the PHP upgrade, the maintenance personnel to the new environment after the test staff to ask me to make frequent errors (error: Prompt to find the file). I traced the code, which was the mistake of the Smarty's local newspaper.

Error: The file reported here does not exist.

Thinking Process:

1, I thought that the program does not have this file, the results found that the document is there, that is how it?

2, later I guess is not the PHP kernel has a problem, I took the relevant kernel file PHP read it again, did not find the problem. As a result, I told the project manager the whole process. --It didn't work out, so let it go. The escalation of the matter was delayed first.

Today I found this problem, my first reaction is that the PHP version is not upgraded, found no. --and then set the entire directory to 777 is OK (chmod 777-r directory). I think it is not the file_exists () method problem.

So, I have done the relevant debugging and experiment.

Debugging the Process debug code:

Directory:

Observe each permission: Test does not have any permission to WWW, while execute file index.php have read and write Execute permission, include file Test.txt have read and write permission.

Operation Result:

The execution permission of the directory affects file_exists () 1, giving test a maximum permission--755

Now that it succeeds, the file_exists () function is limited by the permissions of the directory.

What kind of directory permissions affect File_exists ()?

I did a few experiments:

1, the file of any parent directory, only write permission times file does not exist;

2, the file of any superior directory, only read the permission is also reported that the file does not exist;

3, and when all the parent directory has execute permission, the paper is present, everything is normal.

As a result, file_exists () is recursive to determine if a file exists, and whether it has execute permissions for each directory.

Modify the file path to a relative path and produce the same result.

Summary in the PHP manual does not mention that file_exists will be affected by the directory's execution permissions. This article tells the developers who have this problem. Just take this as a ring. Additional information thank you for leaving the words, very useful. After everybody's opinion I checked the manual again, indeed, if the directory does not have the execution permission, the PHP-FPM application process cannot go to this directory to carry on the file search, certainly thought that the file does not exist (actually thinks that the executable directory does not exist). Manual content, you can consider together, mainly the implementation of permissions. In this case, the reading and writing permissions are not discussed (generally well understood).

Clearly, there is a clear indication of the permission to execute the directory. Execute permissions on the directory are the right to be searched.

Recommended if this article is helpful to you, or let you solve such problems, please recommend a, so that the brothers have a stronger motivation to write.

http://www.bkjia.com/PHPjc/1116380.html www.bkjia.com true http://www.bkjia.com/PHPjc/1116380.html techarticle PHP talk about the pit dad file_exists, file_exists introduction I found a problem, today and share with you. I'll describe the whole process. The problem company has a framework based on Smar ...

  • Related Article

    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.