One of them fixes an annoyance with Firefox and may save some bandwidth, the other two are a bit of polish.
1) Enable proper client-side caching by making the script support HTTP conditional GET.
First off, you must send a Last-Modified header with each image. This can be done with something like
Code: Select all
$lastmodstring = gmdate ('D, d M Y H:i:s \G\M\T', filemtime ($imagefile));
header ('Last-Modified: ' . $lastmodstring);Code: Select all
$etagvalue = '"' . md5_file ($imagefile) . '"';
header ('Etag: ' . $etagvalue);Code: Select all
$headers = getallheaders();
if (isset ($headers["If-Modified-Since"])) {
if (isset ($headers["If-None-Match"]) {
if ($headers["If-Modified-Since"] == $lastmodstring) {
if ($headers["If-None-Match"] == $etagvalue) {
header ('HTTP/1.1 304 Not Modified');
ob_end_clean ();
exit ();
}
}
}
}Note: IE seems to have some funky aggresive caching, and doesn't rely on this, but it makes Firefox (and me) happy.
For more info on HTTP Conditional GET, see here.
2) Send a filename for the file. Something like strip_id_YYYY-MM-DD
Code: Select all
header ('Content-Disposition:inline; filename="1310_2004-10-29.png"');3) Send a file length
Code: Select all
$image = file_get_contents ('$imagefile');
header ('Content-Length: ' . strlen ($image));Barring any typos, the above should be correct. I hope you find it useful.
Cheers, and thanks for the great comic.




