Forum Moderators: coopster

Message Too Old, No Replies

image update problem

         

flashzeus

11:52 am on Jun 29, 2004 (gmt 0)

10+ Year Member



I have created form where images is uploaded to the server. All is normal but if you'll attempt upload image upon old image, browser(IE) will show old one! But if you'll refresh window, all is ok, it will show new image. It is affected only in explorer window, file is uploaded normally. What I need to do I could upload image without refreshing window?

Warboss Alex

12:04 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



That's to do with IE's caching stuff, and it doesn't just apply to IE.

When you display the image, just append a random number/character string after the image extension, i.e. image.gif?123abc

The browser treats this as a different request, so it'd always load the image afresh. This renders caching pretty useless though.

To do your random number thing, all you need is something like this:

$r = md5(rand(0,999));
echo "<img src='/path/to/image.gif?$r>";

Warboss Alex

12:05 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Wait, I just thought of something better.

$r = md5(time());

Avoids the need for generating a random number, so it's probably faster anyway.

flashzeus

1:33 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Thank you, Warboss! All work fine!

Warboss Alex

3:29 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



:)

Glad to help.