getimagesize() returns dimensions of wrong file
Posted: Wed May 13, 2009 12:30 am
I have a set of three scripts (on a Linux server with PHP 4.4.9) which allow users to upload images to my site via an online image editor API and I'm running into some odd behavior. The basic functions of the the scripts are:
upload1.php: Upload form takes user & image to the editor's site, where they edit & resize the image. Image is exported to upload2.php.
upload2.php: Uploaded file is saved with move_uploaded_file(). User is taken to upload3.php with header("Location:...").
upload3.php: Image dimensions are retrieved with getimagesize(). If dimensions are right, new image is displayed. If dimensions are wrong, image dimensions are displayed along with a "Try Again" button. Image is deleted and user is taken back to upload1.php to start process over.
Everything works perfectly unless the Try Again route is taken. Then upload3.php displays the dimensions of the previously-uploaded, incorrect image (along with the "Try Again" button), not the current one (btw, they're both given the same name). However, if I refresh the page, the newly uploaded file is displayed and the upload is declared a success.
I use clearstatcache() after every file_exists() call, so info about the old file should no longer be available. It's almost as if upload3.php executes before upload2.php is done so it's accessing the old file... but that doesn't even make sense, because the old file was deleted the first time through. The more I think about this, the more impossible it seems!!
Anybody have any idea how this could be happening?
upload1.php: Upload form takes user & image to the editor's site, where they edit & resize the image. Image is exported to upload2.php.
upload2.php: Uploaded file is saved with move_uploaded_file(). User is taken to upload3.php with header("Location:...").
upload3.php: Image dimensions are retrieved with getimagesize(). If dimensions are right, new image is displayed. If dimensions are wrong, image dimensions are displayed along with a "Try Again" button. Image is deleted and user is taken back to upload1.php to start process over.
Everything works perfectly unless the Try Again route is taken. Then upload3.php displays the dimensions of the previously-uploaded, incorrect image (along with the "Try Again" button), not the current one (btw, they're both given the same name). However, if I refresh the page, the newly uploaded file is displayed and the upload is declared a success.
I use clearstatcache() after every file_exists() call, so info about the old file should no longer be available. It's almost as if upload3.php executes before upload2.php is done so it's accessing the old file... but that doesn't even make sense, because the old file was deleted the first time through. The more I think about this, the more impossible it seems!!