메뉴 건너뛰기

프로그램언어

조회 수 21699 추천 수 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 [PHP기초] 함수와 객체의 비교 2021.03.27 291
299 PHP웹 보안 취약점 TOP5(웹해킹) 2023.01.12 293
298 비교연산자 ( === 에 관해서 ) 2021.03.25 307
297 콜론 연산자 2021.03.26 307
296 PHP Notice: Use of undefined constant ... assumed ... 오류 2021.03.26 308
295 확장자 추출 하기 2021.03.26 309
294 정규표현식 2021.03.26 311
293 PHP와 HTML과 자바스크립트의 관계 2021.03.26 311
292 쿠키 확인 후 만료시 세션 파괴하는 방법 2020.11.23 314
291 문자열 함수 모음 2021.03.26 318
290 특정일의 주차 구하기 2021.07.08 322
289 TIFF, GIF 여러장 변환 file 2021.03.26 324
288 mysql_free_result(); 관련 오류 2021.03.25 327
287 curl을 이용하여 post, get 방식 으로 데이터 전송하기 2023.01.12 333
286 복권 번호 뽑기 2021.03.26 340
285 AJAX로 해당 페이지에서 COOKIE 사용하기 2021.03.26 359
284 php 암호화 복호화 , 간단한 암호화 2023.01.12 366
283 HEREDOC <<< ( PHP에서 echo로 HTML쉽게 표시하기 ) 2021.03.26 371
282 문자,숫자 랜덤 출력 2021.03.26 407
281 php date 날짜 관련 함수 file 2021.03.27 411
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved