Harikrishnan
Harikrishnan

Reputation: 9979

showing old image even after new image is being uploaded

I'm uploading file using php and displaying it as soon as uploading competed. Sometimes it shows old image, doesn't showing newly uploaded. but hitting refresh will display new image. How can I get rid of this? I'm using apache web server.

Upvotes: 3

Views: 3138

Answers (3)

Prasad N
Prasad N

Reputation: 543

This way you can keep it cached as long as it is not modified, and serve the fresh image as soon as it is modified.

<img src="image.jpg?t=<?php echo filemtime('image.jpg'); ?>" />

Note: This will not disable cache completely But serve fresh image if available.

Upvotes: 4

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

you're getting cached image, to append random value to you image source, like:

your_image.png?t=<?php echo time(); ?>

Upvotes: 4

Raptor
Raptor

Reputation: 54278

it is due to browser's cache. Try to add a random number in filename path, e.g.

<img src="image.jpg?rand=<?php echo rand(); ?>" />

of course, the rand is generated by random function ( PHP / Javascript ) each time.

Upvotes: 6

Related Questions