모바일에서 첨부파일 다운로드 안되거나 다운로드 된것이 정상적으로 안열릴때
제 서버 환경에서만 그럴 수 있겠습니다만, PC에서는 첨부파일이 잘 다운로드 되었지만,
저는 이상하게 모바일에서는 pdf 파일을 다운로드 하면
모바일 - 크롬에서는 다운로드 되지만 파일 안열림.
모바일 - 파폭에서는 다운로드 자체가 안됨.
이었습니다. 그래서 구글링 후 삽질 끝에 작성한 코드 공유 합니다.
이걸 하니, 다 정상인것 같은데, 역시 모바일 파폭에서는 download.php 라는 이름으로만
다운로드가 되고, pdf 뷰어에서 잘 열리기는 하네요..
파폭에서도 잘될 수 있도록 개선점 발견하시는 분 계시면 댓글 부탁드리면서,
저는 귀차니즘으로 파폭은 무시 ㅎㅎㅎ 하렵니다.
-------------------
/bbs/download.php 에서 95행 이하 주석 처리 후 다음 코드를 붙여넣으면 됩니다.
function output_file($file, $name, $mime_type='')
{
if(!is_readable($file)) die('File not found or inaccessible!');
$size = filesize($file);
$name = rawurldecode($name);
$known_mime_types=array(
"htm" => "text/html",
"exe" => "application/octet-stream",
"zip" => "application/zip",
"doc" => "application/msword",
"jpg" => "image/jpg",
"php" => "text/plain",
"xls" => "application/vnd.ms-excel",
"ppt" => "application/vnd.ms-powerpoint",
"gif" => "image/gif",
"pdf" => "application/pdf",
"txt" => "text/plain",
"html"=> "text/html",
"png" => "image/png",
"jpeg"=> "image/jpg",
"hwp"=> "application/x-hwp",
"docx"=> "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"xlsx"=> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"pptx"=> "application/vnd.openxmlformats-officedocument.presentationml.presentation"
);
if($mime_type==''){
$file_extension = strtolower(substr(strrchr($file,"."),1));
if(array_key_exists($file_extension, $known_mime_types)){
$mime_type=$known_mime_types[$file_extension];
} else {
$mime_type="application/force-download";
};
};
@ob_end_clean();
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header('Content-Type: ' . $mime_type);
header('Content-Disposition: attachment; filename="'.$name.'"');
header("Content-Transfer-Encoding: binary");
header('Accept-Ranges: bytes');
if(isset($_SERVER['HTTP_RANGE']))
{
list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
list($range) = explode(",",$range,2);
list($range, $range_end) = explode("-", $range);
$range=intval($range);
if(!$range_end) {
$range_end=$size-1;
} else {
$range_end=intval($range_end);
}
$new_length = $range_end-$range+1;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $range-$range_end/$size");
} else {
$new_length=$size;
header("Content-Length: ".$size);
}
$chunksize = 1*(1024*1024);
$bytes_send = 0;
if ($file = fopen($file, 'r'))
{
if(isset($_SERVER['HTTP_RANGE']))
fseek($file, $range);
while(!feof($file) &&
(!connection_aborted()) &&
($bytes_send<$new_length)
)
{
$buffer = fread($file, $chunksize);
echo($buffer);
flush();
$bytes_send += strlen($buffer);
}
fclose($file);
} else
die('Error - can not open file.');
die();
}
set_time_limit(0);
$tmp = strpos(strrev($original), '.');
$temp = strlen($original) - $tmp;
if($tmp)
$strExt = substr($file_name, strlen($strName) + 1, strlen($file_name));
else
$strExt = ''; //확장자 없음
$strExt = strtolower($strExt);
output_file($filepath, $original, $strExt);
댓글 2개
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4404 | ||
| 2544 | 11개월 전 | 942 | ||
| 2543 | 11개월 전 | 842 | ||
| 2542 | 11개월 전 | 745 | ||
| 2541 | 11개월 전 | 774 | ||
| 2540 | 11개월 전 | 1185 | ||
| 2539 | 12개월 전 | 1020 | ||
| 2538 | 12개월 전 | 1003 | ||
| 2537 |
|
12개월 전 | 841 | |
| 2536 | 1년 전 | 1227 | ||
| 2535 |
|
1년 전 | 779 | |
| 2534 |
|
1년 전 | 886 | |
| 2533 |
거북이와두루미
|
1년 전 | 1661 | |
| 2532 | 1년 전 | 794 | ||
| 2531 | 1년 전 | 674 | ||
| 2530 | 1년 전 | 720 | ||
| 2529 | 1년 전 | 1062 | ||
| 2528 |
|
1년 전 | 554 | |
| 2527 | 1년 전 | 1132 | ||
| 2526 | 1년 전 | 744 | ||
| 2525 | 1년 전 | 1107 | ||
| 2524 | 1년 전 | 912 | ||
| 2523 | 1년 전 | 1334 | ||
| 2522 | 1년 전 | 957 | ||
| 2521 | 1년 전 | 1309 | ||
| 2520 | 1년 전 | 1185 | ||
| 2519 | 1년 전 | 1059 | ||
| 2518 |
Lemios
|
1년 전 | 866 | |
| 2517 | 1년 전 | 955 | ||
| 2516 | 1년 전 | 1702 | ||
| 2515 | 1년 전 | 845 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기