I use simple PHP code (zend framework) to resize jpg images on the fly.
Problem is I always end up with HTTP 200 status, instead having 304 and allow browsers to cache images.
I cant get apache headers, function_exists('apache_request_headers') is false, and in server variable I have only
'HTTP_ACCEPT' => 'image/png,image/*;q=0.8,*/*;q=0.5',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_COOKIE' => '***',
'HTTP_HOST' => 'automobi.li',
'HTTP_KEEP_ALIVE' => '300',
'HTTP_REFERER' => 'http://automobi.li/oglas/Opel+Astra/2',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 FirePHP/0.4',
I'm sending
$lastModified = filemtime($path);
$etag = md5_file($path);
$this->getResponse()->setHeader('Content-type', 'image/jpeg');
$this->getResponse()->setHeader('Cache-Control', 'public');
$this->getResponse()->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
$this->getResponse()->setHeader('Cache-Control', 'max-age=86400, must-revalidate');
$this->getResponse()->setHeader('Expires', gmdate('D, d M Y H:i:s', time() + 86400 ) . ' GMT');
$this->getResponse()->setHeader('ETag', $etag);
and I expected HTTP_IF_MODIFIED_SINCE or sth similar in server variable so I can do
if ($this->getRequest()->getHeader('IF_MODIFIED_SINCE') == $lastModified) {
$this->getResponse()->setHttpResponseCode(304);
} else {
$w = (int) $this->_getParam('w');
$h = (int) $this->_getParam('h');
$image->resize($path, $w, $h);
}
Any idea?