메뉴 건너뛰기

프로그램언어

조회 수 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
번호 제목 날짜 조회 수
320 mysql 에러 구문 표시 2014.02.27 20349
319 MYSQL 업데이트 두 번 하기 2014.02.27 19728
318 php 파일 확장자 2014.02.27 20234
» php 파일 다운로드 구현 2014.02.27 19794
316 해당하는 날짜가 그달의 몇주째인지 계산 2014.02.27 26351
315 FPDF - PHP로 PDF 만들기 2014.02.27 21075
314 [PHP] 한글명 파일 다운로드받기 2014.03.26 20551
313 웹페이지 프린트 하기 html 수준 2014.03.26 19805
312 웹에서 Excel 로 출력하기 2014.03.26 20356
311 jQuery 개발자를 위한 메모 - 플러그 인 2014.03.26 19257
310 JSON and JavaScript usage 2014.03.26 19064
309 jQuery 개발자를 위한 메모 - 레퍼런스 2014.03.26 19522
308 특수문자 없애는 정규표현식 2014.03.26 21623
307 이미지 워터마크 구현 2014.03.26 19667
306 Drag/Drop HTML elements 2014.03.26 19535
305 네이버 지도 api php버전 2014.03.26 19434
304 PHP 소스 : 이미지 리사이즈, 섬네일 2014.03.26 20704
303 어떤 스마트폰으로 접속했는지 알아내는 소스 , (안드로이드 아이폰 ) 2014.03.26 17716
302 PHP 세션에서 시작, 변수등록, 변수삭제, 부수기 2014.03.26 19490
301 PHP 에서의 소켓(Socket) 통신 2014.04.12 20395
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved