팁/튜토리얼

외부 이미지 저장 애드온 수정하기(4)

2016.02.07 06:02
822
0
0

애드온 : 외부 이미지 저장 애드온

제작자 : 카르마

수정자 : 하얀마법 / 배포자 : tofinder

표기버전 : 0.4.7

설치경로 : ./addons/auto_outimage/

 

네번째 팁인데 그렇게 도움되는 건 없습니다;;

 

PHP에서 이미지의 URL 노출과 다운로드를 막아보자

http://b.redinfo.co.kr/21

 

이미지를 가져오려고 하다보면 확장자를 jpg, gif, png 등 정상적으로 좀 쉽게 작성해둔 곳도 있으나,

이미지를 못 가져가게 하려고 막아놓은 곳도 있습니다.

확장자를 asp, jsp, php 등으로 꾸미고 이미지를 출력해주는 곳이 있는데,

그런 경우 다시 기본 확장자를 이미지 확장자로 변경해서 해줘야 합니다.

이 역할을 

$ri_localfile = geRitLocalFile($src,$ri_avoid_domain,'Y');

이 부분에서 확인해볼 수 있는데요,

ri_localfile은 가져오는 이미지 경로를 추출하는 역할을 합니다.

이 기능을 담당하는 것이 geRitLocalFile()이라는 함수인데, php 기본 함수가 아니라,

auto_outimage.func.php 에서 정의된 자체 함수입니다. (함수라고 표현하는 게 맞는지는 잘 모릅니다만;)

 

이제 이 geRitLocalFile()에 대해서 알아보기로 합니다. ㅠㅠ

 

function geRitLocalFile($src,$ri_avoid,$permanent='N') {
   $url = parse_url($src);
   $domain = str_ireplace('www.','',$url['host']);
   $path_parts = pathinfo($url['path']);
   $dir = $path_parts['dirname'];
   $fn = $path_parts['basename'];

       if(in_array($domain,$ri_avoid)) return $src;

   $dir =  cleanUrlRi($dir);
   $fn = cleanUrlRi($fn);

   if($permanent == 'Y') $f = './files/attach/outimage/';
       else $f ='./files/cache/outimage/';
       $tmp_folder = sprintf('%s%s%s',$f.$domain,$dir);
   if(!is_dir($tmp_folder)) FileHandler::makeDir($tmp_folder);
       $tmp_file = sprintf('%s%s%s/%s',$f,$domain,$dir,$fn);
   if(!preg_match("/\.(jpg|png|jpeg|gif|php)$/i",$tmp_file)) $tmp_file = $tmp_file.".gif";
   if(file_exists(realpath($tmp_file))) return str_replace('./','',$tmp_file);
       else if(FileHandler::getRemoteFile($src, $tmp_file)) return str_replace('./','',$tmp_file);
   else return $src;
   }

 

(아직 작성 중입니다...)

 

eond Lv. 12

댓글 0