이미지로드를 수행하는 빠른 PHP 스크립트를 작성할 수 있습니다.당신은 모든 이미지에서 분리 디렉토리에이 과정 스크립트를 넣어 다음과 같이 여기에 연결할 수 있습니다
<img src="http://blah.blahblah.edu/path/to/scripts/image.php" id="c" />
그리고 image.php 파일은 다음과 같이 보일 것이다 :
$file = '/path/to/yourimage.png';
$size = getimagesize($file);
$type = $size['mime'];
header('Content-type: '.$type);
print file_get_contents($file);
exit;
을
물론 image.php에 변수를 제공하고 image.php 파일에서 특정 파일을 가져올 수 있습니다. 예를 들어
:
<img src="http://blah.blahblah.edu/path/to/scripts/image.php?n=<?=base64_encode('my_image.png')?>" id="c" />
PHP는 $_GET
변수에 대한 검사 :
if(isset($_GET['n'])) {
$file = '/path/to/'.base64_decode($_GET['n']);
if(file_exists($file)) {
$size = getimagesize($file);
$type = $size['mime'];
header('Content-type: '.$type);
print file_get_contents($file);
exit;
}
}
편집 :를 나는 당신의 그림을 다운로드 등록 된 사용자에 대해 걱정하고 다른 의견에 읽어 보시기 바랍니다. 또한 hotlinking을 막을 수 있습니다 (해당 항목에도 관심이있는 경우). 상단에 image.php 파일에이를 포함시켜야합니다.
//Don't allow hotlinking
$referer = explode("/", $_SERVER['HTTP_REFERER']);
if($referer[2] != "blah.blahblah.edu") {
$my_img = imagecreate(265, 90);
$background = imagecolorallocate($my_img, 0, 0, 255);
$text_color = imagecolorallocate($my_img, 255, 255, 0);
$line_color = imagecolorallocate($my_img, 128, 255, 0);
imagestring($my_img, 4, 30, 25, "Hot Linking Not Permitted", $text_color);
imagestring($my_img, 4, 30, 50, "blah.blahblah.edu", $text_color);
imagesetthickness($my_img, 5);
imageline($my_img, 30, 45, 230, 45, $line_color);
header("Content-type: image/jpeg");
imagejpeg($my_img);
exit;
}
http://blah.blahblah.edu/random/123/456이 표시되지 않도록 URL을 숨겨야합니다. 해당 폴더에 많은 중요한 희귀 이미지가있어서 사용자가 enmasse를 다운로드하지 못하도록하고 싶습니다. . –
은 폴더 보호 기능을 제공하므로 마이클 Irigoyen이 제안한 것처럼 PHP (또는 유사한) 스크립트를 통해서만 콘텐츠에 액세스 할 수 있습니다 ... 그러면 htdocs 폴더 계층 구조 외부에 파일을 저장할 수도 있습니다 –