프로그램개발/ServerSide(PHP,Node.js)

[펌]이미지 절대 못가져가게 하기

크레도스 2011. 7. 14. 16:43

http://cafe.naver.com/q69/10378가져갈 방법이 없습니다.
저장된 정보는 어떻게 한다치지만.
링크 걸수조차 없습니다 ^^;;
소스가 약간 더러우니 주의바랍니다..
[?
#no 를 먼져 입력했을경우입니다.(저의경우 랜덤을 사용했지만. 메리트가 없더군요)
#여기서 no 는 폴더에있는 몇번째 파일인지 정하는겁니다.
#여기서 주서온건데 어느분껀지는 모르겠네요 ㅈㅅ ;;
$headers = getallheaders();
while (list($header, $value) = each($headers)) {
if( $header == "Referer") {
$refer_link=$value;
}
}
#일단 이녀석이 어디서 파일을 요청했는지 알아냅니다.
#저는 일단 서버단위로 차단을 하기때문에 내서버에서의 접속은 무저건 허용
#하여야 겠죠.
#일단 www.mydomain.com 이란 서버가 내서버이다라고 가정하에
$_tmp=$refer_link;
$tmp=explode("/",$_tmp);
$_tmp_host=$tmp[2];
$tmp_host1=$_tmp_host[1];
$tmp_host2=$_tmp_host[2];
$refer_host="${tmp_host1}.${tmp_host2}";
if($refer_host=="mydomain.com") {
#여기서 중요한것은 웹으로의 접속은 절대 차단한다는 것입니다.
#이미지파일은 웹에 있는것이 아니라 로컬 폴더에 존재하게 됩니다.
#리눅스에서는 되련진 테스트안해봐서 모르겠지만 암튼 진행 ^^
#여기서 또 어떤분의 소스를 펌했습니다.
$location="c:/hiddenimg";
$d = dir($location);
$i = 0;
while (false !== ($entry = $d->read()))
{
if ($entry != "." && $entry != ".." && $entry != "Thumbs.db" && $entry != NULL)
{
$entrylist[$i] = $entry;
$i++;
}
}
$d->close();
$total = count($entrylist);
#자 이제 설명 위에서 제가 약간바꾼게 있습니다원본과 조금 다른.
#파일이 없을때와 Thumbs.db 파일을 걸러내겠지요.
#그리고 해당 로컬폴더의 모든 파일과 파일갯수를 얻어왔습니다.
#이제 화면에 뿌려야겠지요?
#일단 걸러진 파일이 어떤 확장자를 가지고있는지 우린 모르죠.
#알아낼려고 다음과같은 방법을썼습니다.(역시 지저분한 소스)
$entry_tmp1=$entrylist[$no];
$entry_tmp2=explode(".",$entry_tmp1);
$entry_end_line=count($entry_tmp2);
$filetype=$entry_tmp2[$entry_end_line];
Header("Content-type: image/${filetype}");
Header("Content-Length: ".(string)($fileSize));
Header("Content-Disposition: attachment; filename=${entry_tmp1}");
Header("Content-Description: PHP3 Generated Data");
Header("Pragma: no-cache");
Header("Expires: 0");
$fp=fopen("${location}/${entry_tmp1}","r+");
if(fpassthru($fp)) {
flush();
}
else {
fclose($fp);
exit;
}
#자이제 화면에 뿌렸습니다.
#그런데 어떻게 가져갈수있을까요 ?
#가져갈수있는분 있나요 ?
}
else {
#이곳에서 엉뚱한 이미지를 뿌려주거나 else 부터 } 까지 삭제 해주면 반응하지 않습니다.
}
?]