오류해결 | 그누보드 /bbs/download.php 다운로드시 파일 깨짐 | |||||
---|---|---|---|---|---|
작성자 | 작성일 | 18-03-08 19:13 | |||
< 환경 > * 우분투 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(); |
|||||
|
댓글목록
등록된 댓글이 없습니다.