메뉴 건너뛰기

프로그램언어

조회 수 19809 추천 수 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
번호 제목 날짜 조회 수
100 애니메이션 gif 와 일반 gif 구분 하기 2019.01.16 1332
99 dddotag - 허용하지 않는 태그 걸러내기 2019.01.16 1866
98 input 자동완성기능 끄기 2019.02.19 1234
97 PHP http 를 https 로 전환(redirect), http->https 2019.02.19 2197
96 PHP 가변변수 $$ file 2019.02.19 1463
95 PHP에서 UTF와 EUC-KR 변환 2019.02.19 1571
94 PHP $_SERVER 함수 2019.02.25 1574
93 utf-8 문자열을 주어진 바이트로 자르기 2019.04.29 1377
92 주간단위 시작일에서 종료일을 셀렉트박스로 만들기. file 2019.04.29 1361
91 PHP 외부 XML 파싱 하기 2019.06.24 1963
90 PHP 버전이 낮아 imagerotate() 함수가 없을때 대신 사용하는 함수 2019.12.31 661
89 사진이 회전되서 올라갈 경우 2020.05.25 791
88 다중 파일을 zip으로 묶어받기 2020.06.19 653
87 파일 다운로드 함수(멀티 이어받기/속도제한) 2020.06.19 633
86 멀티 파일다운로드 꽁수로 구현하기 2020.06.19 454
85 사업자등록번호 유효성 체크 2020.08.24 486
84 네이버 지도 API를 이용한 주소를 좌표로 변환하기 (PHP) 2020.09.22 512
83 Javascript 두 좌표 사이의 거리 구하기, 두 좌표의 중앙 좌표 구하기 file 2020.09.23 552
82 cUrl를 이용한 json 데이타 주고 받기 2020.09.28 1269
81 13자리 timestamp 생성하기 file 2020.09.28 664
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved