I found a problem and share it with you today. Let me describe the whole process.
Problem
The company has a framework written based on smarty. I am responsible for the upgrade of PHP. After the maintenance staff deployed the new environment, the testers came to me and asked me frequently An error is reported (error: file cannot be found). I traced the code and it turned out to be an error reported by smarty.
Error: The file reported here does not exist.
Thought process:
1. I thought it was because there was no such file in the program, but it turned out that the file was. What happened?
2. Later, I guessed whether there was a problem with the PHP kernel. I looked through the relevant PHP kernel files and found no problem. As a result, I told the project manager about the entire process. ——The matter has not been resolved, so let’s just let it go. The upgrade is delayed for now.
I discovered this problem again today. My first reaction was whether the PHP version had been upgraded. I found out that it had not. ——Later, I set the entire directory to 777 and everything was fine (chmod 777 -R directory). I wonder if it is a problem with the file_exists() method.
So, I conducted relevant debugging and experiments.
Debugging process
Debugging code:
Directory:
Observe each permission: test does not have any permissions for www, while the execution file index.php has read and write execution permissions, and the included file test.txt has read and write permissions.
Run result:
The execution permission of the directory affects file_exists()
1. Give test the maximum permission - 755
Since it is successful, it means that the file_exists() function is restricted by directory permissions.
So what kind of directory permissions affect file_exists()?
I did a few experiments:
1. In any superior directory of the file, if it only has write permission, the file does not exist;
2. File Any parent directory with only read permission will report that the file does not exist;
3. When all parent directories have execution permission, the file will be reported to exist and everything is normal.
The result shows that file_exists() recursively determines whether each directory has execution permission when determining whether a file exists.
Change the file path to a relative path and get the same result.
Summary
It is not mentioned in the PHP manual that file_exists will be affected by the execution permission of the directory. This article is used to inform developers who also have this problem. Just take this as a warning.
Additional information
Thank you everyone for your comments, they are very useful. After everyone's opinions, I checked the manual again. Indeed, if the directory does not have execution permissions, the php-fpm application process cannot search for files in this directory. Of course, it will be considered that the file does not exist (actually it is considered that there is no executable directory). does not exist).
You can consider the contents of the manual together, mainly about execution permissions. I won’t go into details about read and write permissions here (generally they are easy to understand).
Obviously in the manual, there are clear instructions on the execution permission of the directory. Execute permission on the directory means having the right to be searched.
Recommendation
If this article is helpful to you or helps you solve this kind of problem, please recommend it. Let me have stronger motivation for writing.

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
