간단한 캐싱 시스템이이를 수행합니다. 같은 HTML 파일을 감안할 때 :
<body>
<img src="imagesource.php?file=1" />
</body>
을 당신이 좋아하는 이미지 데이터 소스 (imagesource.php) 만들 수 있습니다
<?php
$files = array(
'http://somesite.com/image_to_cache.gif',
'http://somesite.com/image_to_cache2.gif'
);
if(!isset($_REQUEST['file']) || !isset($files[$_REQUEST['file']])) {
header('HTTP/1.0 404 Not Found');
exit;
}
// do we already have the cached file?
$requested_file = $files[$_REQUEST['file']];
$cache_dir = '/tmp/cached_images';
$cache_file = md5($requested_file);
$cache_path = $cache_dir . '/' . $cache_file;
header('Content-Type: image/gif');
if(file_exists($cache_path)) {
readfile($cache_path);
exit;
}
//need to create the cache.
$data = file_get_contents($requested_file);
file_put_contents($cache_path, $data);
echo $data;
그들은 이미 다운로드되지 않은 경우 로컬 원격 이미지를 캐시 할
을, 요청시 브라우저에 출력 할 수 있습니다.
"사용자 생각 이미지가 내 사이트에서 오는 것"이유는 무엇입니까? – joetsuihk
원본 사이트의 정책에 따라 "캐싱"또는 "도난"이라고합니다. 그들이 이미지 사용에 신경 쓰지 않는다면, 캐싱은 호의입니다. 만약 그렇다면, 나는 매우 조심 스러울 것이다. –
""사용자의 이미지가 내 사이트에서 오는 것이라고 생각합니다. "왜?"; 누군가 elses의 일을 신용하고 출자합니까? –