Forum Moderators: coopster
Add/Remove/Modify images for products. However when I do a "modify" in which i upload a new image and replace the older one (with the same name). It still displays the old image unless i refresh the page, at which point it shows the correct and latest uploaded image.
I am assuming this is due to browser caching... is there any way around this?
Thanks,
Ryan
<?php
/*
some basic checking
*/
if (!isset($_GET['ímage'])) exit;
$ImageFile = $_GET['ímage'].".jpg";
if (!file_exists($ImageFile)) exit;
$Size = filesize($ImageFile);
/*
send out all headers
*/
header("HTTP/1.1 200 OK");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-Type: image/jpg");
header("Content-Length: $Size");
/*
and finally the image itself
*/
readfile($ImageFile);
?>
You could also send a 404 header in case something is wrong at the 2 'exit' statements.
Regards,
Arjan
Eg. something.gif becomes something.gif?1162906555
So you save the image as something.gif but when creating the database entry, you append the value of time() to the end. This means that every time you modify the image, the image name will "change" however caching of unmodified images still works.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");