Changeset 1183

Show
Ignore:
Timestamp:
07/22/08 23:38:50 (4 months ago)
Author:
_ck_
Message:

force browser inline image caching if possible

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bb-attachments/trunk/bb-attachments.php

    r1182 r1183  
    422422                        } 
    423423                         
     424                        $headers = apache_request_headers(); 
     425                        $filemtime=filemtime($fullpath); 
     426                        $httpcode="200"; 
     427                        if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $filemtime)) {$httpcode="304";}                                 
    424428                        if (ini_get('zlib.output_compression')) {ini_set('zlib.output_compression', 'Off');}    // fix for IE 
    425                         // header ("Cache-Control: public, must-revalidate, post-check=0, pre-check=0"); 
    426                         // header("Pragma: hack"); 
     429                        header('Last-Modified: '.gmdate('D, d M Y H:i:s', $filemtime).' GMT', true, $httpcode); 
     430                        header("Cache-Control: Public"); 
     431                        header("Pragma: Public"); 
     432                        header("Expires: " . gmdate("D, d M Y H:i:s", time() + (86400 * 30)) . " GMT"); 
    427433                        header("Content-Type: ".$mime); 
    428                         header("Content-Length: $file->size"); 
    429                         header('Content-Disposition: inline; filename="'.$file->filename.'"'); 
    430                         header("Content-Transfer-Encoding: binary");               
    431                         ob_clean(); 
    432                         flush();  
    433                         $fp = @fopen($fullpath,"rb"); 
    434                                 set_time_limit(0);  
    435                         fpassthru($fp); // avoids file touch bug with readfile 
    436                         fclose($fp);                                                                                     
     434                        if ($httpcode=="200") {                  
     435                                header("Content-Length: $file->size"); 
     436                                header('Content-Disposition: inline; filename="'.$file->filename.'"'); 
     437                                header("Content-Transfer-Encoding: binary");               
     438                                ob_clean(); 
     439                                flush();  
     440                                $fp = @fopen($fullpath,"rb"); 
     441                                        set_time_limit(0);  
     442                                fpassthru($fp); // avoids file touch bug with readfile 
     443                                fclose($fp);                     
     444                        }                                                                                        
    437445                        }                
    438446                exit();          
     
    440448} else { 
    441449        $im=@imagecreatetruecolor(1,1); 
     450        header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0"); 
    442451        header("Content-type: image/png"); 
    443452        header("Content-Length: ".strlen($im));