ramasaig — 2010-12-15T04:20:07-05:00 — #1
I have a script which allows a visitor to the web site to upload an image. Since this replaces an earlier image, it gets given the same name (desirably). The upload, and the renaming happen OK. But when all is committed to the database and the visitor is shown the result, the old image is still visible. Clearing the browser cache and refreshing the screen (manually) shows the new image.
Is there a way I can get PHP (or JS, I suppose) to do this automatically as part of the script ?
system — 2010-12-15T05:29:52-05:00 — #2
one way to force a reload of the image every time the page is loaded is to append a unique query string to the filename of the <img>'s src. So even though the filename will be the same, the unique query string will be different thus forcing the browser to download the image again because the url for the image will be different on each page load.
I normally use the current date/time for the unique query string.
ramasaig — 2010-12-15T05:40:28-05:00 — #3
Thanks. That's a good suggestion. At first sight I wasn't sure if I could do that, because the file name is being drawn from a database (one reason for retaining the same image filename). But it should be possible to append a query string at some later point. I'll look into it.
system — 2010-12-15T05:57:57-05:00 — #4
something along this line:
$today = date("F j, Y, g:i a");
echo '<img src="pic1.jpg?myPic='.urlencode($today).'" alt="" />';
in your case you would need to build the string for the img src by appending the current date/time to the file name of the image that was retrieved from the database
ramasaig — 2010-12-15T06:12:46-05:00 — #5
Thanks for the extra pointers. I've got it set up much as you suggest, and it seems to be working a treat (why would it not ?). A bit more testing, though, to make sure there's no unexpected consequence.
To make matters more exciting, it's all within a loop so I've got to make sure the date/time variable gets refreshed every pass, or it will fail in it's purpose. But that's just detail. The main problem is resolved. Thanks again.