Forum Moderators: coopster

Message Too Old, No Replies

Refreshing a picture after upload

Getting the browser to display a picture correctly.

         

Alina

9:58 am on Sep 10, 2004 (gmt 0)

10+ Year Member



Hi

I am creating a user manager area where my user is able to manage their suppliers. Part of this managment includes the uploading of a supplier's picture. And I have adopted the following procedure:
1. Select a supplier. 2. Change (form) information of supplier details. 3. Upload picture. 4. An option to go back to point1.

When I arrive at point 4. the new picture has been uploaded correctly. But when I go thru again - to steps 1 and then 2 - to modify the same supplier - the previous picture is being displayed rather than the new one. But if I hit browser refresh, then i see the new picture.

How do i get the new picuture to be displayed automatically? I am using IE6. And am already using the following meta-tags (which don't seem to work):
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

Please could you help?

Hester

10:22 am on Sep 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could try adding an unused random variable to the end of the image address. This will force the browser to refresh it.

Eg:


srand((double)microtime()*1000000);
echo '<img src="image.jpg?r='.rand().'">';

py9jmas

10:38 am on Sep 10, 2004 (gmt 0)

10+ Year Member



And am already using the following meta-tags (which don't seem to work):
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

That's because you're setting the meta tags on the HTML, not the picture.

and return the correct HTTP headers for the request for the picture.

[edited by: jatar_k at 5:02 pm (utc) on Sep. 10, 2004]
[edit reason] removed url [/edit]

Hester

10:59 am on Sep 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But don't headers have to be the first thing on a page?

Robber

11:06 am on Sep 10, 2004 (gmt 0)

10+ Year Member



I'd go with hester on this one, we do something like on one of our admin scripts and it works great.

Alina

11:35 am on Sep 10, 2004 (gmt 0)

10+ Year Member



Hi Hester i have just tried this and it works great. Thank you very much.

Hester

11:57 am on Sep 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note: if you use PHP 4.2.0 or later, you don't need the "srand((double)microtime()*1000000);" bit as it's done for you apparently. Also make sure you only use that line of code once on the page. (You can use the other line more than once though.)

Alina

12:24 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



I am using PHP 4.3.4. Will use srand only once like you suggest. The pictures are being displayed fine - so i think that i won't investigate why this is happening in PHP 4.3.4 :-)

many thanks for all your help and quick responses. It is much appreciated.

Alina

12:29 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



ohh i understand - i previously misunderstood your message. But i have got it now! Sorry.

Hester

12:38 pm on Sep 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just use rand() - you should be OK without the other bit of code.