메뉴 건너뛰기

프로그램언어

조회 수 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 23Dec
    by
    2016/12/23 Views 23083 

    addslashes — 문자열을 슬래시로 인용

  2. PHP 삼항연산자 ?

  3. phpexcel을 이용한 PHP로 엑셀파일 읽기와 생성

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

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

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

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

  6. No Image 14Apr
    by
    2015/04/14 Views 22401 

    PHP 파일 다루기

  7. PHP에서 CSV 파일 export

  8. No Image 23Dec
    by
    2016/12/23 Views 22206 

    array_key_exists 배열에서 key가 존재하는지 확인

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

    PHP에서 조건문 처리

  10. No Image 23Dec
    by
    2016/12/23 Views 21970 

    파일 확장자 비교

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

    접속 IP 검사

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

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

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

    php 파일 다운로드 구현

  14. No Image 06Mar
    by
    2017/03/06 Views 21695 

    PHPExcel 클래스를 이용해 Excel 2007~2010 의 xlsx 파일 읽기 (100만 행 까지)

  15. No Image 27Mar
    by
    2017/03/27 Views 21681 

    파일시스템, 폼 파일업로드 관련 함수

  16. No Image 27Feb
    by
    2014/02/27 Views 21627 

    날짜 계산하기 (하루전 날짜 구하기)

  17. No Image 26Mar
    by
    2014/03/26 Views 21623 

    특수문자 없애는 정규표현식

  18. No Image 23Dec
    by
    2016/12/23 Views 21604 

    array_push 배열 끝에 하나 이상의 요소를 추가

  19. No Image 27Feb
    by
    2014/02/27 Views 21422 

    유용한 함수 모음

  20. No Image 23Dec
    by
    2016/12/23 Views 21302 

    call_user_func 사용자가 정의한 함수를 호출하여 실행고자 할 때 사용

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

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved