Yes, you can... I found a pretty thorough script that does just what you want. Here it is:
<?php
# get filename
$filename = $_GET['image'];
# check if valid
if (!@file_exists($filename) || !@is_readable($filename)) die("The selected Image does not exist.");
else $lastmod = @filemtime($filename) or die("Error while trying to read the 'Last Modified'-Information.");
# check if 'sending' is necessary (using cache functions)
$sendbody = true;
# get file content
$content = file_get_contents($filename);
# check 'If-Modified-Since' header
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && gmdate('D, d M Y H:i:s', $lastmod)." GMT" == trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
header("HTTP/1.0 304 Not Modified");
header("Content-Length: 0");
$sendbody = false;
}
# check 'If-None-Match' header (ETag)
if ($sendbody && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
$inm = explode(",",$_SERVER['HTTP_IF_NONE_MATCH']);
foreach ($inm as $i) {
if (trim($i) != $etag) continue;
header("HTTP/1.0 304 Not Modified");
header("Content-Length: 0");
$sendbody = false; break;
}
}
# caching headers (enable cache for one day)
$expires = 60 * 60 * 24;
$exp_gmt = gmdate("D, d M Y H:i:s",time()+$expires)." GMT";
$mod_gmt = gmdate("D, d M Y H:i:s",$lastmod)." GMT";
header("Expires: {$exp_gmt}");
header("Last-Modified: {$mod_gmt}");
header("Cache-Control: public, max-age={$expires}");
header("Pragma: !invalid");
# send image
if ($sendbody) {
$size = @filesize($filename) or openError("Error while trying to read the Filesize",lastURI());
header("ETag: {$etag}");
header("Content-Type: image/jpeg");
header("Content-Length: {$size}");
echo $content;
}
# don't send
else {
header("Content-Type: !invalid");
}
exit;
?>
Save that as like image.php. Then you can use it like:
<img src="image.php?image=yay.jpg">
That would display yay.jpg. You can modify it to do whatever you want. If you need anymore help, let me know. By the way, most of that was found at php.net and was not written by me.