...

View Full Version : Image overwrite problem!



ConfusedOfLife
10-25-2003, 01:43 PM
Hi

My situation is too simple, I'm having an image in my page displayed to clients, ok? I also have a form in the same page that accepts an image file to be uploaded. The image that is uploaded via this form should take the place of the image that's displayed in the page. I always use one name for that image: "main.jpg" and when a new image is uploaded, I move it to the same directory and name it as "main.jpg", which means it overwrites the previous image. So, some lines after the PHP code that does this, I'm having my normal HTML img tag that shows the image.

But the problem is that whenever I upload an image, it still shows the previous image in the page and only if I press F5, it'll change it. I'm sure that the new image overwrites the previous one (I go to the directoy and check it!!), but I dunno why it doesn't show the new one. I think even though my HTML code is after my PHP code, but b4 it excecutes the PHP code, it'll read the image and because of that I still get the old image when I press the Upload button. I really don't know what to do to change the order, any help is greately appriciated.

bijan

Nightfire
10-25-2003, 03:39 PM
I believe it's just the browser caching the old image, and as the image name is the same as last time, it knows no different. I solved this problem by using the following:



$img = '<img src="imagename.jpg?'.rand(1,9999999999).'">';

ConfusedOfLife
10-25-2003, 07:53 PM
Yes, yes, it's browser caching, but your trick doesn't work for me! I tried it but I still get my old picture. Any help?? PLEASEEEEEE

firepages
10-27-2003, 03:16 AM
you can do no more than Nightfire suggests , view-source , is the random string actually being added to the imagename ? if so is it random ?

if you have php <4.2 then seed the random number first (it should still work without but try anyway)



<?php
srand( mktime( ) ) ;
$img = '<img src="imagename.jpg?'.rand(1,9999999999).'">';
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum