I am currently using the script below to output the contents of a JPEG straight from a file. The reason I'm doing so is because I'm using mod_rewrite/php to mask the name of the original file. This is working partially as expected, except that Safari insists on downloading the photo instead of just allowing me to see it in the browser. Am I missing a header? Also, what modifications could I make to improve performance?
error_reporting(0);
// Find which image we're trying to get
$_GET['id'];
// In the real script, I do some proccessing here
$filename = $_GET['id'] . '.jpg';
// Getting headers sent by the client.
$headers = apache_request_headers();
// Checking if the client is validating his cache and if it is current.
if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == filemtime($filename))) {
// Client's cache IS current, so we just respond '304 Not Modified'.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT', true, 304);
} else {
// Image not cached or cache outdated, we respond '200 OK' and output the image.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT', true, 200);
header('Content-Length: '.filesize($filename));
header('Content-Type: image/jpeg');
print file_get_contents($filename);
}
?>
Teşekkürler!