메뉴 건너뛰기

프로그램언어

조회 수 21721 추천 수 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;
?> 

  1. jquery 이용 아이디 중복체크 실시간

    Date2014.04.12 Views20353
    Read More
  2. htmlentities <-> html_entity_decode (엔티티

    Date2014.04.12 Views30634
    Read More
  3. iframe 사용시 iframe의 높이가 내용의 높이만큼 자동으로 조절

    Date2014.04.12 Views21877
    Read More
  4. php 파일 다운로드 구현

    Date2014.04.12 Views21721
    Read More
  5. php한글체크를 위한 정규표현식

    Date2014.04.12 Views22469
    Read More
  6. PHP 로그인후 현재 페이지로 돌아오기 처리

    Date2014.04.12 Views22676
    Read More
  7. 한글줄바꾸기 또는 utf-8 wordwrap

    Date2014.04.12 Views26548
    Read More
  8. [PHP] POST 로 넘어온 모든 변수값 확인하기

    Date2015.03.25 Views23359
    Read More
  9. POST값 통째로 인코딩하기

    Date2015.04.06 Views21183
    Read More
  10. [PHP] 서버 운영하시는분 서버 꺼졌을때 메시지 띄우기

    Date2015.04.06 Views20339
    Read More
  11. 홈페이지 귀퉁이에 붙이는 공지창

    Date2015.04.06 Views25440
    Read More
  12. 문자열 붙이기

    Date2015.04.14 Views19359
    Read More
  13. PHP에서 조건문 처리

    Date2015.04.14 Views22070
    Read More
  14. 문자열 나누기

    Date2015.04.14 Views19698
    Read More
  15. 문자열 치환하기

    Date2015.04.14 Views20513
    Read More
  16. PHP 변수전달 GET, POST

    Date2015.04.14 Views26603
    Read More
  17. 접속 IP 검사

    Date2015.04.14 Views21884
    Read More
  18. MySQL DB 중복여부 검사하여 없는 것만 추가

    Date2015.04.14 Views20167
    Read More
  19. addslashes 함수의 필요성

    Date2015.04.14 Views24264
    Read More
  20. fopen 파일 열기

    Date2015.04.14 Views20313
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved