首页 > php代码 > php 断点续传程序

php 断点续传程序

<?php
function sendfile($myFile) {
    $mm_type = "application/octet-stream";
    $fp = fopen($myFile, 'rb');
    $size = filesize($myFile);
    ob_start();
    header("Cache-Control: public, must-revalidate");
    header("Pragma: hack");
    header("Content-Type: " . $mm_type);
    header('Content-Disposition: attachment; filename="' . $fname . '"');
    header("Content-Transfer-Encoding: binary ");
    if (isset($_SERVER['HTTP_RANGE']) && ($_SERVER['HTTP_RANGE'] != "") && preg_match("/^bytes=([0-9]+)-/i", $_SERVER['HTTP_RANGE'], $match) && ($match[1] < $size)) {
        $range = $match[1];
        fseek($fp, $range);
        header("HTTP/1.1 206 Partial Content");
        //header("Date: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($myFile)) . " GMT");
        header("Accept-Ranges: bytes");
        $rangesize = ($size - $range) > 0 ? ($size - $range) : 0;
        header("Content-Length:" . $rangesize);
        header("Content-Range: bytes " . $range . '-' . ($size - 1) . "/" . $size);
        //header("Connection: close"." ");
        
    } else {
        header("Content-Length: " . (string)($size));
        header("Accept-Ranges: bytes");
        $range = 0;
    }
    fpassthru($fp);
    ob_end_flush();
}


本文地址:http://www.phprm.com/code/32833.html

转载随意,但请附上文章地址:-)

标签:none

发表留言