В настоящее время я использую приведенный ниже скрипт для вывода содержимого JPEG прямо из файла. Я делаю это потому, что я использую mod_rewrite / php для маскировки имени исходного файла. Это работает частично, как и ожидалось, за исключением того, что Safari настаивает на загрузке фотографии, а не просто позволяет мне видеть ее в браузере. Я пропускаю заголовок? Кроме того, какие изменения я могу сделать, чтобы улучшить производительность?
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);
}
?>
Спасибо!