오류해결 | 그누보드 /bbs/download.php 다운로드시 파일 깨짐
작성자
< 환경 >

* 우분투 10.04 서버
* PHP 판번호: PHP Version 5.3.2-1ubuntu4.7
* 서버 사양: P4 1.7GHz, 512MB RAM
* Mod-security 모듈 작동중이고, 기타 외산 오프소스 방화벽 OS 별도 가동 중...

다름 아니라, 위의 환경에서, 게시판에 첨부한 파일을 클릭하여 내려받기 하면, 파일이 깨져있습니다. (혹은 정상적으로 열리지 않음. 예를 들면, 그림파일들, zip, doc 등등)

이 문제로, /bbs/download.php 에서,

아래 부분을 모두 주석 처리하고,
----------------------------------------------------------
if(preg_match("/msie/i", $_SERVER[HTTP_USER_AGENT]) && preg_match("/5\.5/", $_SERVER[HTTP_USER_AGENT])) {
    header("content-type: doesn/matter");
    header("content-length: ".filesize("$filepath"));
    header("content-disposition: attachment; filename=\"$original\"");
    header("content-transfer-encoding: binary");
} else {
    header("content-type: file/unknown");
    header("content-length: ".filesize("$filepath"));
    header("content-disposition: attachment; filename=\"$original\"");
    header("content-description: php generated data");
}
header("pragma: no-cache");
header("expires: 0");
flush();
---------------------------------------
아래의 코드로 대체할 때, 정상적으로 파일이 열리게 됩니다.

* 아래 코드 출처 - http://kr2.php.net/manual/en/function.header.php 참조 (2011년 1월 31일자 User Contributed Notes)

  // Must be fresh start
  if( headers_sent() )
    die('Headers Already Sent');

  // Required for some browsers
  if(ini_get('zlib.output_compression'))
    ini_set('zlib.output_compression', 'Off');

// Parse Info / Get Extension
$fsize = filesize($filepath);
$path_parts = pathinfo($filepath);
$ext = strtolower($path_parts["extension"]);

    // Determine Content Type
    switch ($ext)
    {
      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;
      default: $ctype="application/force-download";
    }

    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: $ctype"); 
    header("Content-Disposition: attachment; filename=\"".$original."\";" ); 
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".$fsize);
    ob_clean();
    flush();

댓글목록

등록된 댓글이 없습니다.

총 게시물 93 개, 페이지 2 RSS
제목 작성자
오류해결 apachectl start시 httpd: apr_sockaddr_info_get() failed for 123-123-123-123.youiwe.co.kr 오류해결 H
오류해결 아파치가 정상적으로 작동하는데 페이지가 열리지 않는 경우 H
오류해결 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (… H
오류해결 Field 'name' doesn't have a default value 오류해결 H
오류해결 php 5.4이상 로그인이 정상적으로 되지 않거나 홈페이지가 정상적으로 보이지 않는 경우 H
오류해결 cannot find sfc.dll plese re-install this application 오류해결 H
오류해결 Cannot start session without errors, please check errors given in your PHP and/or webserver log file… H
오류해결 Warning Cannot modify header information 오류해결 H
오류해결 ERROR 1040 (08004): Too many connections H
오류해결 Allowed memory size of 8388608 bytes exhausted 오류해결 H
오류해결 그누보드 /bbs/download.php 다운로드시 파일 깨짐 H
JavaScript & jQuery jQuery Ajax 한글 깨짐 해결방법 H
오류해결 알디터 SCRIPT5007: 정의되지 않음 또는 null 참조인 'nodeName' 속성을 가져올 수 없습니다. H
기타 환율정보 / 금은금액 정보 H
기타 robots.txt H
게시물 검색