note 106705 added to function.header

From: Date: Tue, 29 Nov 2011 19:39:39 +0000
Subject: note 106705 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-184810@lists.php.net to get a copy of this message
Expanding on some above comments, here is a file serving mechanism with cache. I found bugs in previous examples that every other request would not properly cache: if (file_exists($file)) { $mtime = filemtime($file); $headers = getallheaders(); // if Browser sent ID, we check if they match if (isset($headers['If-None-Match']) && $headers['If-None-Match'] == $mtime) { header('HTTP/1.1 304 Not Modified'); header("ETag: {$mtime}"); header("Cache-Control: public, must-revalidate"); // HTTP/1.1 exit; } else { header("ETag: {$mtime}"); header("Accept-Ranges: bytes"); header("Content-Length: " . filesize($file)); header("Content-Type: " . mime_content_type($product->photo)); header("Content-Disposition: inline; filename=\"{$product->photo}\";"); header("Cache-Control: public, must-revalidate"); // HTTP/1.1 ob_clean(); flush(); readfile($file); exit; } } else { die("Image not found" . $product->photo); } ---- Server IP: 69.147.83.197 Probable Submitter: 216.14.33.10 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- https://master.php.net/note/edit/106705 Del: integrated -- https://master.php.net/note/delete/106705/integrated Del: useless -- https://master.php.net/note/delete/106705/useless Del: bad code -- https://master.php.net/note/delete/106705/bad+code Del: spam -- https://master.php.net/note/delete/106705/spam Del: non-english -- https://master.php.net/note/delete/106705/non-english Del: in docs -- https://master.php.net/note/delete/106705/in+docs Del: other reasons-- https://master.php.net/note/delete/106705 Reject -- https://master.php.net/note/reject/106705 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184810) next »