메뉴 건너뛰기

프로그램언어

조회 수 21696 추천 수 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
번호 제목 날짜 조회 수
220 내 계정 용량 체크 2019.01.08 1595
219 사업자번호로 사업자 종류알기 2019.01.08 1222
218 디비내용을 엑셀 파일로 다운로드 시키는 방법 2019.01.08 1391
217 php/asp에서 가상번호 부여와 가상번호를 거꾸로 적용 2019.01.08 1429
216 php에서 체크박스 선택한 것 보여주기 file 2019.01.08 1799
215 배열을 테이블로 만들기 2019.01.08 1620
214 include 와 namespace 2019.01.08 1080
213 파일 2019.01.08 1226
212 디렉토리의 제어 2019.01.08 1214
211 PHP 문자열에서 검색어를 기준으로 앞뒤로 일정 길이만큼 자르기 2018.10.27 3539
210 PHP 랜덤확률 구하기 2018.10.27 4759
209 PHP 소켓을 이용하여 URL의 응답결과를 문자열로 받기 2018.10.27 3502
208 PHP 랜덤 문자열 생성 2018.10.27 4120
207 PHP XML 문서파싱 (SAX 방식 , DOM 방식) file 2018.10.27 3585
206 PHP split()와 explode()의 차이점 2018.10.27 3534
205 PHP eregi가 빠를까, strpos가 빠를까? 2018.10.27 4091
204 PHP 확장 모듈을 이용한 C 라이브러리 사용 2018.10.27 3783
203 자바스크립트 이스케이프 문자열을 PHP로 디코딩 하기 2018.10.27 3259
202 이미지 땡겨와서 출력하기 2018.09.28 5282
201 DB 연동 4단 셀렉트 박스 2018.09.28 6063
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved