Reputation:
I have a image upload tool written in php.
Users may chose a file, and it gets uploaded with a certain filename, then if the user regrets chosing that file they may click the file-input and upload another file instead, BUT THE FILENAME IS THE SAME, so the browser caches the first image uploaded. And instead of the second image the browsers display the first one instead, even though it's another image uploaded.
Kindof hard to explain...
How can I solve this?
Thanks
Upvotes: 2
Views: 2599
Reputation: 371
I've seen something like this before, but it was the other way around in that I was sending a file down from the server to the browser. The file name didn't change but the content should have, but it kept showing the original file's content.
I fixed it by changing a setting in php.ini :
session.cache_limiter = nocache
Upvotes: 0
Reputation: 53929
Either disable caching of images in your web server or append a random query string to the src
of your image.
By "random query string" I mean that you append something that changes on every request to the URL of the image. Something like this:
<img src="http://www.example.com/image.jpg?<?php echo Time () ?>" />
Time () returns the current TIMESTAMP and will change on every request, and so the URL will always be different and thus forcing the browser to download the image every time.
Upvotes: 12