Uploaded photos and cache problem...

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
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Uploaded photos and cache problem...

Post 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?
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

if it is the cache, then

Code: Select all

header("Cache-Control: no-cache, must-revalidate");
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post 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.
cyrenity
Forum Newbie
Posts: 3
Joined: Mon Oct 24, 2005 7:45 am

Post 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 ;)
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks a lot! That's a great method!
Post Reply