메뉴 건너뛰기

프로그램언어

조회 수 19798 추천 수 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 파일 이름에서 확장자 추출마스터 2017.03.07 20066
319 파일 업로드 (중복처리) 2017.03.06 20191
318 파일 삭제 2015.04.14 25335
317 파일 및 데이타베이스 백업 2019.01.08 1611
316 파일 다운로드 함수(멀티 이어받기/속도제한) 2020.06.19 624
315 파일 output을 return 하기 2021.03.26 244
314 파일 2019.01.08 1227
313 특정일의 주차 구하기 2021.07.08 324
312 특수문자 없애는 정규표현식 2014.03.26 21628
311 템플릿 관련 정보 2016.08.22 20733
310 태그 또는 멘션 소스 뽐아내기방법 2019.01.16 1251
309 키를 이용한 암호화/복호화 함수입니다. 2018.07.24 5744
308 클래스와 인스턴스 그리고 메소드 만들기 2021.03.27 235
307 큰따옴표(") 와 작은따옴표(') 2021.03.25 274
306 쿠폰번호 발행 업데이트판. (간단한 클래스화[PHP4 기준] 등...) 2018.07.19 6091
305 쿠키변수받기 2014.02.27 29231
304 쿠키 확인 후 만료시 세션 파괴하는 방법 2020.11.23 319
303 콜론 연산자 2021.03.26 308
302 코드 생성 하기 2023.01.12 216
301 체크박스, post 로 넘기고 받아서 다시 체크하기, checkbox 2017.03.07 21138
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved