다운로드 더이상 해메지 맙시다 > PHP

본문 바로가기
사이트 내 전체검색

PHP

다운로드 더이상 해메지 맙시다

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 6,052회 작성일 21-02-09 11:43

본문

달식이



 다운로드 땀시 엄청 고생한 사람입니다. 더이상 저같이 헤메지 마시길

 환경
 아파치 1.3.20
 php 4.3.0
 mysql 3.23.58

문제의 증상
1. 한글 파일 다운로드 안됨
2. 파일이 깨져서 나옴
3. 파일 이름 띄어쓰기 있으면 에러남
4. 파일 열기 안됨

 해결
1. 2. 4 번 문제 공통 해결책

 플로러 6.0 기준 코드 입니다. 익스 버전별 코드는 팁엔테크 게시판에 많이 나와 있으므로 참고 하세요.

 ************* 가장 중요한것 한가지 !!! include 는 절대 안됩니다. include 하면 실제 파일과
 다운로드 되는 파일 사이에 약 4바이트 정도 차이가 난다고 하네요.. 결과적으로 해당 응용프로그램이 포맷을 인식 하지 못합니다. 그냥 하드 코딩 하는 방식으로 해결 했는데 다른 방법
 이 있으신분은 리플 주세요***********************************

header("Content-Type: application/octet-stream");
 Header("Content-Disposition: attachment;; filename=$원래파일이름");
header("Content-Transfer-Encoding: binary");
 Header("Content-Length: ".(string)(filesize($filepath)));
 Header("Cache-Control: cache, must-revalidate"); <--파일열기를 위한 캐시컨트롤!!!(지송빠트렸었네요!!!)
header("Pragma: no-cache");
 header("Expires: 0");
 $fp = fopen($filepath,'r+b') ;
 if (!fpassthru($fp)) {
            fclose($fp);
        }
  }

 3. $filepath = addslashes($filepath); 추가로 공백 해결!

이상 허접한 팁이지만 제가 워낙 고생헌거라서 ~~~ 많이들 봐주시고 잘못된점 질책주세요!

구럼 !!!


출처...
http://phpschool.com/bbs2/inc_view.html?id=11022&code=tnt2&start=0&mode=search&field=title&search_name=&operator=and&period=all&category_id=&s_que=%B4%D9%BF%EE%B7%CE%B5%E5


 ======================================================
 <?
 session_start();

 if (!$id){
        echo "
        <script>
            alert ('해당 파일이 없습니다.');
            self.close();
        </script>
        ";
        exit;
 }

 $DATA_dir = "절대경로";

include ("$DATA_dir/db접속.php");
 $connect= db_connect("DBname");


 $tmp_file = split("\.","파일명");
 $ext = strtolower($tmp_file[count($tmp_file)-1]);
                       
 $file = "{$DATA_dir}/upload/존재하는 파일명";
 $dnfile = "다운받을 이름명";

 $dn = "1"; // 1 이면 다운 0 이면 브라우져가 인식하면 화면에 출력
$dn_yn = ($dn) ? "attachment" : "inline";
 $bin_txt = "1";
 $bin_txt = ($bin_txt) ? "r" : "rb";

 if(eregi("(MSIE 5.0|MSIE 5.1|MSIE 5.5|MSIE 6.0)", $HTTP_USER_AGENT)){
        if(strstr($HTTP_USER_AGENT, "MSIE 5.5")){
                header("Content-Type: doesn/matter");
                Header("Content-Length: ".(string)(filesize("$file")));
                Header("Content-Disposition: filename=$dnfile");
                Header("Content-Transfer-Encoding: binary");
                Header("Pragma: no-cache");
                Header("Expires: 0");
        }

        if(strstr($HTTP_USER_AGENT, "MSIE 5.0")){
                Header("Content-type: file/unknown");
                header("Content-Disposition: attachment; filename=$dnfile");
                Header("Content-Description: PHP3 Generated Data");
                header("Pragma: no-cache");
                header("Expires: 0");
        }

        if(strstr($HTTP_USER_AGENT, "MSIE 5.1")){
                Header("Content-type: file/unknown");
                header("Content-Disposition: attachment; filename=$dnfile");
                Header("Content-Description: PHP3 Generated Data");
                header("Pragma: no-cache");
                header("Expires: 0");
        }

        if(strstr($HTTP_USER_AGENT, "MSIE 6.0")){
                Header("Content-type: application/x-msdownload");
                Header("Content-Length: ".(string)(filesize("$file"))); // 이부부을 넣어 주어야지 다운로드 진행 상태가 표시
                Header("Content-Disposition: attachment; filename=$dnfile");
                Header("Content-Transfer-Encoding: binary");
                Header("Pragma: no-cache");
                Header("Expires: 0");
        }
 } else {
        Header("Content-type: file/unknown");
        Header("Content-Length: ".(string)(filesize("$file")));
        Header("Content-Disposition: $dn_yn; filename=$dnfile");
        Header("Content-Description: PHP3 Generated Data");
        Header("Pragma: no-cache");
        Header("Expires: 0");
 }

 if (is_file("$file")) {
        $fp = fopen("$file", $bin_txt);

        if (!fpassthru($fp))
        fclose($fp);
 } else {
        echo "해당 파일이나 경로가 존재하지 않습니다.";
 }
 ?>

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

  • 게시물이 없습니다.

접속자집계

오늘
2,073
어제
4,039
최대
6,642
전체
830,588
contact : webmaster@beautipia.co.kr
Copyright © beautipia.co.kr. All rights reserved.