PHP는

2011-12-29 2 views
6

에 의해 생성 된 이미지를 캐시하는 방법을 내가 get 메소드PHP는

에 의해 정의 W 및 H와 이미지 파일을 인쇄 할 파일을했지만 내 문제는 내가이 헤더를 추가이 사진

를 캐시하는 것입니다 파일이

@header("Cache-Control: private, max-age=10800, pre-check=10800"); 
@header("Pragma: private"); 
@header("Expires: " . date(DATE_RFC822,filemtime($full_path))); 

if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) 
     && 
    (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($full_path))) { 
    // send the last mod time of the file back 
    header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($full_path)).' GMT',true, 304); 
    exit; 
}else 
{ 
    @header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($full_path)) . ' GMT'); 
    @header('Content-Type: image/jpeg'); 
    @imagejpeg($image); 
} 

하지만 내 문제는 일부 사진 확인 캐시,하지만 다른 사람이 아니며, 언젠가는 앨범 내 사진이 아닌 내가 캐시 헤더를 사용하지 않으면 때까지 표시입니다

는 m입니다 y 헤더가 맞습니까? , 그리고 캐시에 대해 사용해야합니까 - 또는 + 시간 캐시를 설정하는 방법은?

+3

그것은 그런 모든 오류를 숨길 수있는 좋은 방법이 아니다. PHP의 [error_log ini 지시어] (http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log)를 설정하여 오류를 추적하는 대신 오류를 추적 할 수 있도록하십시오. – cmbuckley

+0

나는 매일 PHP를 사용하고 @가 처음에는 무엇 인지도 몰랐다. –

+0

'@'는 오류를 인쇄하지 않고 자동 모드에서 function을 실행하는 것과 같이 존재하면 함수 오류를 숨기는 첫 번째였습니다 –

답변

1

mod_expires와 함께 Htaccess를 사용하기 때문에?

예 # 1 :

# enable expirations 
ExpiresActive On 
# expire GIF images after a month in the client's cache 
ExpiresByType image/gif A2592000 
# HTML documents are good for a week from the 
# time they were changed 
ExpiresByType text/html M604800 

Read This Documentation

예 2 :

ExpiresActive On 
ExpiresDefault A0 
ExpiresByType image/gif A2592000 
ExpiresByType image/png A2592000 
ExpiresByType image/jpg A2592000 
ExpiresByType image/jpeg A2592000 
+0

갤러리의 모든 그림을 엄지와 큰 것으로 캐시 할 것입니까? ,이 코드를 사용하여 감사합니다. 매우 유용했습니다. –

+1

@JackKFouani : 그렇다면 _accept_ 대답은 –

+0

입니다. Htaccess (Apache 2+ 및 Mod_Expires)의 예제 ... 설명서를 읽으십시오. :) –