Page 1 of 1

file_exists is attempting to deceive me

Posted: Thu Apr 12, 2007 8:03 am
by titaniumdoughnut
I've got a site where users are allowed to upload profile photos. When they do, several versions at different sizes are made, and the database value for 'photo' in the row for their account is incremented by +1. This is so that the file path changes when the image changes, and if they upload a new one, it won't be cached. That's not the problem though.

Before an image is used, I make sure it exists:

Code: Select all

$thumbpath = "propic/" . $value["ID"] . '_' . $value["photo"] . '_a.jpg';
if(file_exists($thumbpath)){
$thumbsize = getimagesize($thumbpath);
}
Now, every so often this results in a big nasty error:

Code: Select all

Warning: getimagesize(propic/200_3_a.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/9007/domains/take247.com/html/php/movielisttools.php on line 311
I think this happens when the user screws up the image upload somehow, resulting in a database value for photo (it's looking for the third upload attempt here) and a server which thinks the file exists, but no file. I've checked via URL and FTP, and the file does not exist, yet file_exists says it does. How might I combat this deceptive file_exists() result?

Posted: Thu Apr 12, 2007 8:09 am
by feyd
maybe you need to call clearstatcache() or use more functions like is_file() and is_readable(). Making sure the user can't botch the upload (at least not affecting the database in the process) may be a good idea too. ;)