This question is for my understanding, I can live with they way things are, but, if I could change it that would be even better.
Here’s the issue: when file_exists() is used in PHP running under Apache, the function will not return TRUE as it should unless the file has the group execute bit set. This doesn’t make sense to me because I thought the execute bit was only need for files that were to be executed. A file being examined by an executing piece of code should read just as long as the read bit is set as far as I know.
A little more information:
The file is a .png, e.g.: image.png.
OpenSUSE 11.4
PHP is version 5.3.8
Apache version is 2.2.17
The permissions and owner of the file being read are: 754 reg:web-dev
Apache is running as user wwwrun:www. It has the group web-dev added to it as well.
If the file’s permissions are 744 PHP’s file_exists() will always return FALSE
If the file’s permissions are 754 PHP’s file_exists() will return TRUE to show that file exists (as it should)
The annoying part about this is that there are many PHP files that are actually being executed but they don’t need more than 644 to execute so why would file_exists() need the group execute bit as well (654 or 754).
A second part to this question is, is this something that could be changed somehow? I.e., make it so only the read bit is required. Then more reasonable permissions for an image could used like 644 or even 640.
On 2012-01-30 08:16, Reg gie wrote:
> The annoying part about this is that there are many PHP files that are
> actually being executed but they don’t need more than 644 to execute so
> why would file_exists() need the group execute bit as well (654 or
> 754).
My guess is that the files are called differently.
–
Cheers / Saludos,
Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)
Am 30.01.2012 08:16, schrieb Reg gie:
>
> A little more information:
> The file is a .png, e.g.: image.png.
What is the exact parameter you pass to the function (means: do you just
put the file name in and expect it to be resolved via the automatic
search paths or do you give it a full path)?
Even better post a minimal code snippet which shows it so that we can
reproduce, something like that
<?php
$filename = '/path/to/image.png';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
where you show the real path instead of the dummy I posted now.
I will test it later when I have access to my PC.
–
PC: oS 11.4 (dual boot 12.1) 64 bit | Intel Core i7-2600@3.40GHz | KDE
4.6.0 | GeForce GT 420 | 16GB Ram
Eee PC 1201n: oS 11.4 64 bit | Intel Atom 330@1.60GHz | KDE 4.8.0 |
nVidia ION | 3GB Ram
I abandoned pursuing this investigation because as I was working on some PHP code I found a PHP command that stated that it required the execute bit. I can’t remember which one it was but I think it was a directory command of some sort. In any case if one reasonably common file system command requires the execute bit according to the documentation it’s best that I just leave it set and not concern myself about the rest.