getimagesize() returns dimensions of wrong file

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
gr8dane
Forum Newbie
Posts: 19
Joined: Wed Aug 22, 2007 3:12 am

getimagesize() returns dimensions of wrong file

Post by gr8dane »

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!! :banghead: Anybody have any idea how this could be happening?
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: getimagesize() returns dimensions of wrong file

Post by Griven »

I experienced a similar behavior a short while back. I had a form to update a record in a database, and it would submit to itself. The code to update the database would run, but the form would display the data from before it had been modified--that is until I pressed the submit button again. It would then show the new data.

My problem was that I was calling the $_POST variables after the form rendered, when they needed to be called before it.

Let me know if that helps or not.
Post Reply