title: PHP file_exists() returning false on some files
body: <p>I'm having a strange problem with the <code>file_exists()</code> PHP function on a Linux server.</p>
  
  <p>When using file_exists to check the image is on the server before editing it, it will sometimes fail for no apparent reason. File paths are absolute and I've checked them through ssh they are 100% at the specified path.</p>
  
  <p>The images that fail file_exists() will still display in the browser. The code doesn't make a difference a basic <code>var_dump(file_exists('/home/user/path/image.jpg'));</code> will return false.</p>
  
  <p>The file permissions/ownerships are exactly the same on all images and parent directories. Safe mode is off. There are no PHP errors. I'm stumped now and not sure what to look for.</p>
  
  <p>Here is how the images are on the server:</p>
  
  <pre><code>/home/user/public_html/images/location/1.jpg -- will work
  /home/user/public_html/images/location2/1.jpg -- won't work
  /home/user/public_html/images/location2/2.jpg -- will work
  </code></pre>
  
  <p>I have root access to the server so if anyone has any ideas I will happily try them out.</p>
  
  <p>Thanks in advance for your advice, let me know if you need extra info.</p>
  
  <p><strong>EDIT:</strong>
  To answer the questions in the comments below.</p>
  
  <ul>
  <li>Yes the images are there, it's definitely not caching.</li>
  <li>Safe mode is off (I already mentioned this in my post).</li>
  <li>Paths are not symlinks but direct links to the files location on the server.</li>
  <li>Phoenix, it is consistent. The working files will always work and vice versa. The names are 1.jpg, 1.thumb.jpg, etc. so it's not a problem with strange characters or spaces.</li>
  </ul>
  
  <pre><code>[root@server ~]# ls -l /home/user/public_html/images/Hawkhurst/
  total 92
  -rwxr-xr-x  1 user user 24501 Aug 11  2009 1.jpg
  -rwxr-xr-x  1 user user  1672 Aug 11  2009 1.thumb.jpg
  -rwxr-xr-x  1 user user 14983 Aug 11  2009 2.jpg
  -rwxr-xr-x  1 user user  1370 Aug 11  2009 2.thumb.jpg
  -rwxr-xr-x  1 user user 17238 Aug 11  2009 3.jpg
  -rwxr-xr-x  1 user user  1453 Aug 11  2009 3.thumb.jpg
  -rwxr-xr-x  1 user user 14168 Aug 11  2009 4.jpg
  -rwxr-xr-x  1 user user  1464 Aug 11  2009 4.thumb.jpg 
  [root@server ~]#
  </code></pre>
  
  <p>I have tried with permissions 777 and 755 which make no difference. For example in this folder, 1 and 2 may work whilst 3 &amp; 4 don't...</p>
  
  <p>I ran a quick test to see what apache/php runs as and they do run as nobody, but this does not explain why some images work and some don't with the exact same permissions.</p>
  
  <p><strong>EDIT 2:</strong> Problem solved. Can't believe how stupid it was, some of the filenames which were called from a database had spaces at the end... Whoever made the original script didn't run any sort of cleaning up before saving them.</p>