[이상락]님이 남기신 글:
>안녕하세요...
>산이님이 phpschool에 올려주신 내용에 대한 문의가 있어 이렇게 글을 올림니다.
>
>이벤트 핸들러에 대한 액션이 동작할때 제일아래쪽의
>readfile($img);
>에 의해 이미지가 출력되는 것 같은데 ..
>제가 test해 보니 이미지를 "aa.jpg"를
>아파치 에러로그에 /action.php/aa.jpg에서 찾는 로그가 남더라구요 ...
>이것을 어찌해야 하는지 ..
>Action에 대해 debug 하는 방법이랑 약간의 설명을 부탁 드립니다.
>
>감사 합니다.
>
action 지시자에 설정한 스크립트 파일은 아파치 access_log 에
기록되질 않습니다. 말그대로 백그라운드 형태로 action 하기 때문이죠.
AddHandler chk-image .gif .png .jpg .jpeg .swf
Action chk-image /actimg.php
이 내용을 VirualHost 각 세션에 설정하지 않고
Global config 부분에 설정하면 모든 가상호스트에 전부적용되므로
주의해야 합니다.
즉 Global config 에 설정하면
virtual_host1_DocumentRoot/actimg.php
virtual_host2_DocumentRoot/actimg.php
Virtual_host3_DocumentRoot/actimg.php
...
이렇게 각각 가상호스트마다 actimg.php 이 있어야합니다.
현재
AddHandler chk-image .gif .png .jpg .jpeg .swf
Action chk-image /action.php
이렇게 설정되어 있는것 같네요. 맞나요?
(action.php 인지 actimg.php 인지 서로 구별하세요)
이렇게 설정했다면
DocumentRoot/action.php 에 action 스크립트 파일이 있어야
하는데 현재 위의 에러로그를 봐서는 DocumentRoot/test/action.php
에 있는것 같네요.
만약 테스트삼아
/test/action.php 이 위치에 action 스크립트 파일을 위치하고자 한다면
AddHandler chk-image .gif .png .jpg .jpeg .swf
Action chk-image /test/action.php
이렇게 설정 해야합니다.
또한 이 설정에서 주의할점은
Global config 에 설정하면 DocumentRoot/test 뿐만 아니라
DocumentRoot/
DocumentRoot/foo/
DocumentRoot/bar/
DocumentRoot/foo/bar/
...
등등 모두 적용되고 또한 각각의 가상호스트도 모두
적용됩니다.
따라서 Action 지시자를 설정할때 적용할 범위와 가상호스트
를 구분해서 적용해야 합니다.
테스트로 다음과 같이 설정하고 디버깅해봅니다.
...
<VirtualHost ...>
...
DocumenRoot /home/user1/public_html
...
<Location /test>
AddHandler chk-image .gif .png .jpg .jpeg .swf
Action chk-image /test/actimg.php
</Location>
</VirualHost>
이렇게 설정하고 아파치 restart
/home/user1/public_html/test/actimg.php
에 actimg.php 파일을 만드세요
(action.php 가 아님)
그리고 간단하게
-- /home/user1/public_html/test/testimg.html -------------
<HTML>
...
...
<H3>이미지 action 테스트</H3>
<IMG SRC='foo.gif' BORDER=1>
</HTML>
----------------------------------------------------------
이렇게 만들고 위의 html 파일을 웹브라우저로 호출해보세요.
물론 /home/user1/public_html/test/foo.gif 파일이 있어야
겠지요
디버깅하는 방법은
actimg.php 파일에서 readfile($img); 이 부분을
지울때와 적용할때 어떻게 브라우저에 나타나는지 서로 비교해
보면 될겁니다.
>
>
>//--- 첨부//---
>
>[Tue Sep 23 18:59:02 2003] [error] [client 218.39.201.56] File does not exist: /usr/local/httpd/htdocs/test/actimg.php/aa/a.jpg, referer: http://61.100.5.66/test.php
>
>
>
>AddHandler chk-image .gif .png .jpg .jpeg .swf
>Action chk-image /actimg.php
>
>이렇게 설정하고,
>
>DocumentRoot/actimg.php 파일에 다음과 같은 비슷한 방법으로 체크하고
>이미지를 클라이언트에게 전송하면 됩니다.
>
><?php
>## get file extension(tail)
>##
>function get_ftail($file)
>{
>$tail = substr(strrchr($file,'.'),1);
>return strtolower($tail);
>}
>
>function get_stype($ftail)
>{
>$stype = array
>(
>'gif' => 'image/gif',
>'jpg' => 'image/jpeg',
>'jpeg' => 'image/jpeg',
>'png' => 'image/png',
>'swf' => 'application/x-shockwave-flash',
>);
>
>return $stype[$ftail];
>}
>
>if(!preg_match(";$_SERVER[HTTP_HOST];",$_SERVER[HTTP_REFERER]))
>{ exit; }
>
>if(!file_exists($img=$_SERVER[PATH_TRANSLATED]))
>{ exit; }
>
>## 그외 $_COOKIE 등등 체크
>
>$header = get_stype(get_ftail($_SERVER[PATH_INFO]));
>
>header('Content-type:'.$header);
>
>readfile($img);
>
>exit; // don't print any messages
>?>
======================================== |