Fighting user's cache with an updated image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PHP General,

The Situation:
I have a form on my web page which uses PHP to upload an image into a user's directory. Because I use the uploaded image in a variety of places in my web site, my script renames the file to conform to naming conventions I use on the site.
Users can keep one image, and they can over write it. Just below the form, it shows their current image. If they upload a new image, it should display the new version.


The Problem:
Even though the file uploads correctly, and it is immediately available, I noticed that sometimes on my own computer the image displayed on the page with the upload form would not update. After much experimentation, I am reasonably sure that this is because the browser's cache is storing the image and loads the cached version and not the new version.
If I clear out the cache after the upload, the newly uploaded image displays. This is not confusing for me, but of course the web site users are bound to find this troublesome.


What I've Tried So Far:
I've considered different naming conventions for files, so that the uploaded file would have a different name, which would get around the cache issue. But because of the existing web site structure which makes extensive use of the file naming convention already in place, it is a very daunting option.
Along the same lines, I considered making a temporary naming convention for that one page, but this tested the limits of my PHP scripting abilities. I can't claim any more skill than a newbie when it comes to PHP.


The Question:
Is there a way I can trick the browser into getting the image file off the server every time and not from the cache, so that it will be clear to user's that they have successfully uploaded their image?


   Any help much appreciated.

--
Dave Gutteridge
dave@xxxxxxxxxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux