Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP is_readable returns true for non-readable file
    primarykey
    data
    text
    <p>I have an image processor PHP script, and it contains the following code:</p> <pre><code> if (!is_dir($fullFile)) { if (is_readable($fullFile)) { $im = getimagesize($fullFile); // Will be FALSE if not an image </code></pre> <p>In some instances, the script will fail at getimagesize with the following error:</p> <pre><code>getimagesize(/path/to/file.jpg) [function.getimagesize]: failed to open stream: Permission denied at www.yada.yada/page.php </code></pre> <p>In this case, the permissions for /path/to/file.jpg are definitely prohibitive (400), so I'd have expected the is_readable test to prevent me getting to that point. Aside from setting permissions differently, what might I do in order to resolve this? Why does it seem that is_readable has an incorrect result? Is it possible that is_readable is operating with the EUID of the file owner, while getimagesize is not? That's the only explanation that makes sense to me, but even that knowledge doesn't help resolve. </p> <p>Prompted by @hek2mgl I created this ultra-complex script, named readable.php:</p> <pre><code>&lt;?php echo is_readable("/stora2/Pics/2009/2009-07-26/DSC00532.JPG") . "\n\n"; ?&gt; </code></pre> <p>Then I switched user to the web server user (actually www-data on this server) and ran it. Result was</p> <pre><code>1 </code></pre> <p>Then I ran strace as that same user. These are the commands I used. The result is a 70KB+ file, and SO won't let me post it in its entirety, so it is posted at <a href="http://pastebin.com/mFqiSBiz" rel="nofollow">http://pastebin.com/mFqiSBiz</a></p> <pre><code>dennis@luke:~$ sudo su - www-data $ ls -l "/stora2/Pics/2009/2009-07-26/DSC00532.JPG" -rw------- 1 dennis dennis 524288 2012-02-11 08:18 /stora2/Pics/2009/2009-07-26/DSC00532.JPG $ file "/stora2/Pics/2009/2009-07-26/DSC00532.JPG" /stora2/Pics/2009/2009-07-26/DSC00532.JPG: writable, regular file, no read permission $ php /home/dennis/readable.php 1 $ strace php /home/dennis/readable.php &gt; /tmp/strace.out 2&gt;&amp;1 </code></pre> <p>Not sure what I'm looking for. Please advise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload