모바일에서 첨부파일 다운로드 안되거나 다운로드 된것이 정상적으로 안열릴때 > 그누보드5 팁자료실

그누보드5 팁자료실

모바일에서 첨부파일 다운로드 안되거나 다운로드 된것이 정상적으로 안열릴때 정보

모바일에서 첨부파일 다운로드 안되거나 다운로드 된것이 정상적으로 안열릴때

본문

제 서버 환경에서만 그럴 수 있겠습니다만, 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);
 

 

 

추천
3

댓글 2개

전체 2,412 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT