메뉴 건너뛰기

프로그램언어

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

  1. No Image 12Apr
    by
    2014/04/12 Views 20341 

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

  2. No Image 12Apr
    by
    2014/04/12 Views 30424 

    htmlentities <-> html_entity_decode (엔티티

  3. No Image 12Apr
    by
    2014/04/12 Views 21862 

    iframe 사용시 iframe의 높이가 내용의 높이만큼 자동으로 조절

  4. No Image 12Apr
    by 조쉬
    2014/04/12 Views 21699 

    php 파일 다운로드 구현

  5. No Image 12Apr
    by
    2014/04/12 Views 22458 

    php한글체크를 위한 정규표현식

  6. No Image 12Apr
    by
    2014/04/12 Views 22662 

    PHP 로그인후 현재 페이지로 돌아오기 처리

  7. No Image 12Apr
    by
    2014/04/12 Views 26546 

    한글줄바꾸기 또는 utf-8 wordwrap

  8. No Image 25Mar
    by
    2015/03/25 Views 23337 

    [PHP] POST 로 넘어온 모든 변수값 확인하기

  9. POST값 통째로 인코딩하기

  10. No Image 06Apr
    by
    2015/04/06 Views 20324 

    [PHP] 서버 운영하시는분 서버 꺼졌을때 메시지 띄우기

  11. No Image 06Apr
    by
    2015/04/06 Views 25426 

    홈페이지 귀퉁이에 붙이는 공지창

  12. No Image 14Apr
    by
    2015/04/14 Views 19353 

    문자열 붙이기

  13. No Image 14Apr
    by
    2015/04/14 Views 22038 

    PHP에서 조건문 처리

  14. No Image 14Apr
    by
    2015/04/14 Views 19681 

    문자열 나누기

  15. No Image 14Apr
    by
    2015/04/14 Views 20492 

    문자열 치환하기

  16. No Image 14Apr
    by
    2015/04/14 Views 26566 

    PHP 변수전달 GET, POST

  17. No Image 14Apr
    by
    2015/04/14 Views 21871 

    접속 IP 검사

  18. No Image 14Apr
    by
    2015/04/14 Views 20157 

    MySQL DB 중복여부 검사하여 없는 것만 추가

  19. No Image 14Apr
    by
    2015/04/14 Views 24250 

    addslashes 함수의 필요성

  20. No Image 14Apr
    by
    2015/04/14 Views 20297 

    fopen 파일 열기

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved