메뉴 건너뛰기

프로그램언어

조회 수 618 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
function fDown($file,$name,$downview,$speed,$limit)// 경로, 원파일명, 다운/보임, 다운속도, 속도제한여부

{
    if(!file_exists($file))
        die('File not exist!');
    $size = filesize($file);
    $name = rawurldecode($name);

    if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']))
        $UserBrowser = "Opera";
    elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']))
        $UserBrowser = "IE";
    else
        $UserBrowser = '';

    // 브라우저 정의
    $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera')? 'application/octetstream' : 'application/octet-stream';
    @ob_end_clean(); // decrease cpu usage extreme
    Header('Content-Type: ' . $mime_type);
    Header('Content-Disposition: $downview; filename="'.$name.'"');
    Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    Header('Accept-Ranges: bytes');
    Header("Cache-control: private");
    Header('Pragma: private');

    // multipart-download and resume-download
    if(isset($_SERVER['HTTP_RANGE']))
    {
        list($a, $range) = explode("=",$_SERVER['HTTP_RANGE']);
        str_replace($range, "-", $range);
        $size2 = $size-1;
        $new_length = $size-$range;
        Header("HTTP/1.1 206 Partial Content");
        Header("Content-Length: $new_length");
        Header("Content-Range: bytes $range$size2/$size");
    } else {
        $size2=$size-1;
        Header("Content-Length: ".$size);
    }
    $chunksize = 1*(1024*$speed); // 속도제한값
    $this->bytes_send = 0;
    if ($file = fopen($file, 'rb'))
    {
        if(isset($_SERVER['HTTP_RANGE']))
            fseek($file, $range);
        while(!feof($file) and (connection_status()==0))
        {
            $buffer = fread($file, $chunksize);
            print($buffer);//echo($buffer); // is also possible
            flush();
            $this->bytes_send += strlen($buffer);
            if($limit) sleep(1); // 다운로드 속도제한
        }
        fclose($file);
    } else
        die('Error can not open file!!');
    if(isset($new_length))
        $size = $new_length;
    die();
    Header("Connection: close");
}

List of Articles
번호 제목 날짜 조회 수
80 stripcslashes — addcslashes()로 인용한 문자열을 되돌림 2016.12.23 20458
79 quotemeta 모든 메타 문자앞에 역슬래쉬를 붙인 문자열을 반환 2016.12.23 20461
78 stripslashes — 따옴표 처리한 문자열을 풉니다 2016.12.23 20486
77 문자열 치환하기 2015.04.14 20493
76 [PHP] 한글명 파일 다운로드받기 2014.03.26 20551
75 HTTP Protocol의 data method - GET / POST 2016.04.22 20637
74 PHP 소스 : 이미지 리사이즈, 섬네일 2014.03.26 20707
73 템플릿 관련 정보 2016.08.22 20732
72 array_slice 배열의 일부를 추출 2016.12.23 20775
71 검색어 처리 루틴 2015.04.14 20778
70 preg_match (정규표현식 매치를 수행합니다) 2016.12.23 20854
69 PHP error 메시지 출력 file 2015.04.14 20924
68 PHP switch 문 file 2015.04.14 20993
67 Ajax로 구연한 실시간 서버시간출력 file 2017.03.06 21032
66 RSSReader Class 제작 및 Reader 만들기 file 2016.08.22 21042
65 FPDF - PHP로 PDF 만들기 2014.02.27 21086
64 PHP continue 문 file 2015.04.14 21097
63 체크박스, post 로 넘기고 받아서 다시 체크하기, checkbox 2017.03.07 21134
62 POST값 통째로 인코딩하기 1 2015.04.06 21175
61 DB 내용을 화면에 출력(이중 for 문) 2015.04.14 21246
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved