library/Garp/Image/File.php
public function show($path, $timestamp = null, $mime = null) {
        $headers = function_exists('apache_request_headers') ?
            apache_request_headers() :
            array();

        if (is_null($timestamp))
            $timestamp = $this->_readTimestampFromFile($path);
        if (is_null($mime)) {
            $mime = $this->_readMimeTypeFromFile($path);
        }

        header("Content-Type: $mime");
        header("Cache-Control: maxage=".(24*60*60).', must-revalidate'); //In seconds
        header("Pragma: public");

        // Checking if the client is validating his cache and if it is current.
        if (
            isset($headers['If-Modified-Since']) &&
            strtotime($headers['If-Modified-Since']) == $timestamp
        ) {
            // Client's cache IS current, so we just respond '304 Not Modified'.
            header('Last-Modified: '.gmdate('D, d M Y H:i:s', $timestamp).' 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', $timestamp).' GMT', true, 200);
            header('Content-Length: '.filesize($path));
            $resource = fopen($path, 'rb');
            rewind($resource);
            fpassthru($resource);
            fclose($resource);
        }
    }
public function show($path, $timestamp = null, $mime = null) {
        $headers = function_exists('apache_request_headers') ?
            apache_request_headers() :
            array();

        if (is_null($timestamp))
            $timestamp = $this->_readTimestampFromFile($path);
        if (is_null($mime)) {
            $mime = $this->_readMimeTypeFromFile($path);
        }

        header("Content-Type: $mime");
        header("Cache-Control: maxage=".(24*60*60).', must-revalidate'); //In seconds
        header("Pragma: public");

        // Checking if the client is validating his cache and if it is current.
        if (
            isset($headers['If-Modified-Since']) &&
            strtotime($headers['If-Modified-Since']) == $timestamp
        ) {
            // Client's cache IS current, so we just respond '304 Not Modified'.
            header('Last-Modified: '.gmdate('D, d M Y H:i:s', $timestamp).' 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', $timestamp).' GMT', true, 200);
            header('Content-Length: '.filesize($path));
            $resource = fopen($path, 'rb');
            rewind($resource);
            fpassthru($resource);
            fclose($resource);
        }
    }
public function show ( $ path , $ timestamp = null , $ mime = null ) { $ headers = function_exists ( 'apache_request_headers' ) ? apache_request_headers ( ) : array ( ) ; if ( is_null ( $ timestamp ) ) $ timestamp = $ this -> _readTimestampFromFile ( $ path ) ; if ( is_null ( $ mime ) ) { $ mime = $ this -> _readMimeTypeFromFile ( $ path ) ; } header ( "Content-Type: $mime" ) ; header ( "Cache-Control: maxage=" . ( 24 * 60 * 60 ) . ', must-revalidate' ) ; //In seconds header ( "Pragma: public" ) ; // Checking if the client is validating his cache and if it is current. if ( isset ( $ headers [ 'If-Modified-Since' ] ) && strtotime ( $ headers [ 'If-Modified-Since' ] ) == $ timestamp ) { // Client's cache IS current, so we just respond '304 Not Modified'. header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' , $ timestamp ) . ' 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' , $ timestamp ) . ' GMT' , true , 200 ) ; header ( 'Content-Length: ' . filesize ( $ path ) ) ; $ resource = fopen ( $ path , 'rb' ) ; rewind ( $ resource ) ; fpassthru ( $ resource ) ; fclose ( $ resource ) ; } }
Lets the browser render an image file
@param String $path The path to the image file
@param String $timestamp Cache timestamp - if not provided, this will have to be found out (at the cost of disk access)
@param String $mime The image mimetype - if not provided, this will have to be found out (at the cost of disk access)
@return Void
Lets the browser render an image file