메뉴 건너뛰기

프로그램언어

조회 수 19794 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<?
   //First, see if the file exists
   if (!is_file($file)) { die("<b>404 File not found!</b>"); }

    //Gather relevent info about file
   $len = filesize($file);
   $filename = basename($file);
   $file_extension = strtolower(substr(strrchr($filename,"."),1));

    //This will set the Content-Type to the appropriate setting for the file
   switch( $file_extension ) {
     case "pdf": $ctype="application/pdf"; break;
     case "exe": $ctype="application/octet-stream"; break;
     case "zip": $ctype="application/zip"; break;
     case "doc": $ctype="application/msword"; break;
     case "xls": $ctype="application/vnd.ms-excel"; break;
     case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
     case "gif": $ctype="image/gif"; break;
     case "png": $ctype="image/png"; break;
     case "jpeg":
     case "jpg": $ctype="image/jpg"; break;
     case "mp3": $ctype="audio/mpeg"; break;
     case "wav": $ctype="audio/x-wav"; break;
     case "mpeg":
     case "mpg":
     case "mpe": $ctype="video/mpeg"; break;
     case "mov": $ctype="video/quicktime"; break;
     case "avi": $ctype="video/x-msvideo"; break;

      //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
     case "php":
     case "htm":
     case "html":
     case "txt": die("<b>Cannot be used for ". $file_extension ." files!</b>"); break;

      default: $ctype="application/force-download";
   }

    //Begin writing headers
   header("Pragma: public");
   header("Expires: 0");
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header("Cache-Control: public"); 
   header("Content-Description: File Transfer");
   
   //Use the switch-generated Content-Type
   header("Content-Type: $ctype");

    //Force the download
   $header="Content-Disposition: attachment; filename=".$filename.";";
   header($header );
   header("Content-Transfer-Encoding: binary");
   header("Content-Length: ".$len);
   @readfile($file);
   exit;
?>

List of Articles
번호 제목 날짜 조회 수
300 GD를 이용한 스팸성 게시물 차단을 위한 보안 단어 입력 예제 2014.02.27 26945
299 glob 현재 디렉토리에서 pattern에 일치하는 경로 이름을 배열로 반환 2016.12.23 19636
298 headers_sent 헤더 전송 여부를 확인 2016.12.23 19405
297 HEREDOC <<< ( PHP에서 echo로 HTML쉽게 표시하기 ) 2021.03.26 371
296 htmlentities <-> html_entity_decode (엔티티 2014.04.12 30405
295 HTTP Protocol의 data method - GET / POST 2016.04.22 20637
294 HTTP 인증하기, 로그인창 띄우기 file 2021.03.26 214
293 http://홈주소/?mode=xxx 하는방법 2017.03.07 17642
292 iframe 사용시 iframe의 높이가 내용의 높이만큼 자동으로 조절 2014.04.12 21862
291 implode — 문자열로 배열 원소를 결합 2016.12.23 19951
290 include 와 namespace 2019.01.08 1087
289 ini_get - php.ini에 지정되어 있는 지시어의 값을 읽어온다 2016.12.23 19520
288 input 자동완성기능 끄기 2019.02.19 1217
287 is_array — 변수가 배열인지 확인 2016.12.23 18048
286 Javascript 두 좌표 사이의 거리 구하기, 두 좌표의 중앙 좌표 구하기 file 2020.09.23 535
285 JAVASCRIPT 차트, 그래프 모음 (php chart, graph ) 2021.03.26 1614
284 jQuery 개발자를 위한 메모 - 레퍼런스 2014.03.26 19522
283 jQuery 개발자를 위한 메모 - 플러그 인 2014.03.26 19257
282 jquery 이용 아이디 중복체크 실시간 2014.04.12 20341
281 JSON and JavaScript usage 2014.03.26 19064
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved