file_exists is attempting to deceive me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

file_exists is attempting to deceive me

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. ;)
Post Reply