메뉴 건너뛰기

프로그램언어

조회 수 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
번호 제목 날짜 조회 수
180 while, for, foreach 속도 비교 2021.03.26 620
179 utf-8 문자열을 주어진 바이트로 자르기 2019.04.29 1356
178 TIME_TO_SEC 시간 포맷 2019.01.16 1381
177 TIFF, GIF 여러장 변환 file 2021.03.26 323
176 text파일에 한줄씩 내용추가하기 2017.03.06 17535
175 Text를 GD 이미지로 뿌리기 2014.02.27 29813
174 substr(), mb_substr(), iconv_substr() 2021.03.26 564
173 stripslashes — 따옴표 처리한 문자열을 풉니다 2016.12.23 20486
172 stripcslashes — addcslashes()로 인용한 문자열을 되돌림 2016.12.23 20442
171 RSSReader Class 제작 및 Reader 만들기 file 2016.08.22 21042
170 RSS json_decone 사용방법 2019.01.16 1430
169 Record Drag/Drop Position 2014.02.27 29201
168 quotemeta 모든 메타 문자앞에 역슬래쉬를 붙인 문자열을 반환 2016.12.23 20461
167 printf() sprintf() 2021.03.26 272
166 preg_match (정규표현식 매치를 수행합니다) 2016.12.23 20843
165 Predefined Variables (미리 정의된 변수들) 2021.03.26 274
164 POST값 통째로 인코딩하기 1 2015.04.06 21175
163 POST, GET으로 배열값 받기(직렬화) file 2017.03.06 23285
162 php한글체크를 위한 정규표현식 2014.04.12 22458
161 PHP폼 사용시 폼 양식에서 값이 사라질때 2019.01.08 1316
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved