메뉴 건너뛰기

프로그램언어

조회 수 19794 추천 수 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 20395 

    PHP 에서의 소켓(Socket) 통신

  2. No Image 26Mar
    by
    2014/03/26 Views 20356 

    웹에서 Excel 로 출력하기

  3. No Image 27Feb
    by
    2014/02/27 Views 20349 

    mysql 에러 구문 표시

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

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

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

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

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

    fopen 파일 열기

  7. CodeIgniter에서 PHPExcel 사용하기

  8. No Image 27Feb
    by
    2014/02/27 Views 20234 

    php 파일 확장자

  9. No Image 23Dec
    by
    2016/12/23 Views 20223 

    깨진 한글 체크

  10. No Image 06Mar
    by
    2017/03/06 Views 20184 

    파일 업로드 (중복처리)

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

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

  12. No Image 07Mar
    by
    2017/03/07 Views 20061 

    파일 이름에서 확장자 추출마스터

  13. No Image 23Dec
    by
    2016/12/23 Views 20051 

    정규표현식 매치를 수행 (preg_match)

  14. No Image 07Mar
    by
    2017/03/07 Views 19977 

    날짜 일수 차이 계산

  15. No Image 22Dec
    by
    2016/12/22 Views 19972 

    PHP Mcrypt 라이브러리를 활용한 암호화 시스템

  16. No Image 23Dec
    by
    2016/12/23 Views 19951 

    implode — 문자열로 배열 원소를 결합

  17. No Image 23Dec
    by
    2016/12/23 Views 19943 

    explode - 문자열 나눔

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

    class_exists 클래스가 정의되었는지 확인

  19. No Image 26Mar
    by
    2014/03/26 Views 19805 

    웹페이지 프린트 하기 html 수준

  20. No Image 27Feb
    by 조쉬
    2014/02/27 Views 19794 

    php 파일 다운로드 구현

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

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved