Page 1 of 1

Uploaded photos and cache problem...

Posted: Wed Oct 26, 2005 3:51 am
by Mr Tech
Hi there,

I have a PHP script that uploads photo onto the server and then displays the photo for you. You can also overwrite an uploaded photo with a new photo if you wish.

My problem is, when I've uploaded a new photo, which overwrites the old photo, it displays the old photo ("on the your photo has upload" page) until you refresh the page... So I'm guessing it saves the old photo in the cache until you refresh the page...

Is there anyway I can force the browser to show the new photo and not the old photo without reloading the page?

Posted: Wed Oct 26, 2005 4:16 am
by mickd
if it is the cache, then

Code: Select all

header("Cache-Control: no-cache, must-revalidate");

Posted: Wed Oct 26, 2005 8:41 pm
by Mr Tech
That didn't work...

Instead, I just made it reload the page once using meta refresh. That seems to fix the problem...

If there is a better way, please elt me know.

Posted: Thu Oct 27, 2005 4:51 am
by cyrenity
yes you can do it , cheat the browser by sending a random string in querystring with image file name ..

here you go;

Code: Select all

<?php
strRand = uniqid(rand());
?>
<IMG SRC="image.png?<?=strRand?>">
enough cheating with browser ;)

Posted: Mon Oct 31, 2005 8:20 pm
by Mr Tech
Thanks a lot! That's a great method!