메뉴 건너뛰기

프로그램언어

조회 수 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
번호 제목 날짜 조회 수
260 PHP error 메시지 출력 file 2015.04.14 20924
259 PHP EXCEL export시 시트 이름 지정하여 여러 시트에 데이터 쓰기 2017.03.06 18266
258 PHP http -> https 로 전환 2023.01.12 236
257 PHP http 를 https 로 전환(redirect), http->https 2019.02.19 2183
256 PHP Mcrypt 라이브러리를 활용한 암호화 시스템 2016.12.22 19972
255 PHP Notice: Use of undefined constant ... assumed ... 오류 2021.03.26 308
254 PHP SimpleHtmlDom Parser로 HTML 파싱하기 2023.01.12 220
253 PHP split()와 explode()의 차이점 2018.10.27 3536
252 PHP str_replace php 문자열치환 2023.01.12 197
251 PHP switch 문 file 2015.04.14 20993
250 php www 붙이기 2023.01.12 234
249 PHP XML 문서파싱 (SAX 방식 , DOM 방식) file 2018.10.27 3585
248 PHP ZIP 압축파일 만들기 file 2023.01.12 251
247 PHP 가변변수 $$ file 2019.02.19 1449
246 php 간단 심플한 달력만들기 file 2023.01.12 241
245 PHP 날짜 함수 2017.04.13 17673
244 PHP 날짜, 시간 관련 함수. date(), mktime() 2017.03.06 16707
243 PHP 날짜/시간 정리 2017.03.07 18629
242 php 내장함수 2017.03.07 17001
241 PHP 네이버블로그 원격 글쓰기 API 소스 file 2018.02.09 12465
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved