Jump to content

How to force a refresh? New image doesn't refresh on page after update...


benphp

Recommended Posts

I have a page that has a user's image on it and a form with a file Browse textbox for uploading a new photo.

 

Once you select the new photo, you click Upload, and it runs through an Upload.php file, then returns to this page.

 

The image doesn't update unless I click F5 (refresh). Even if I put a link to the very same page, the cached image still displays.

 

Any ideas?

Found the answer. It's simple, but makes no sense:

 

<img src="yourimage.jpg?<?php echo time();?>" border="0" alt="" />

 

I've seen images listed like this before. Now I know what the ?var is for.

It gives the image a different name without actually renaming it, which prompts the browser to reload the image as it see's it as a different image.
  • 1 month later...

That answer came just in time for me.  What a clever wheeze ! Thanks benphp and papaface.

 

In my case, the whole statement was already in a php block, so it read like ..

 

echo '<IMG SRC = "../photos/thumbnail/'.$photoCounter.'.jpg?'.time().'" BORDER="0" STYLE = "z-index:1" ALT = "'.$fileName.'">'.PHP_EOL;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.