images doesn't seem to cache
| From: | anders thoresson | Date: | Fri, 05 Nov 2004 11:10:57 +0000 |
| Subject: | images doesn't seem to cache | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-201272@lists.php.net to get a copy of this message | ||
Hi,
I put all my images outside the web root, the prevent direct access, and then access them with a <img>-tag like this:
<img src="fnc_get_image.php?path=<?=$path;?>" />
where fnc_get_image.php is:
// Check if user is logged in
require_once 'global_includes.php';
$user =& new User();
// Get path to image for display
$path = $_GET['path'];
// Prepend path - prevents misuse
$pPath = "/home/username/albums/" . $path;
header("Cache-Control: private");
$extention = substr($path, -3);
if ($extention == "jpg")
header("Content-type: image/jpeg");
if ($extention == "gif")
header("Content-type: image/gif");
if ($extention == "bmp")
header("Content-type: image/bmp");
if ($extention == "png")
header("Content-type: image/png");
readfile("$pPath");
There is one slight problem though: To my eyes, it looks like the images
are downloaded from the server every time. Is this a side effect of this
method or is it just a optical illusion? Is there a way to tell for sure
if the image is downloaded or displayed from the browser cache?
I've tried with and without a Cache-Control header. It doesn't seem to do any difference at all.
Best regards,
Anders