流3gp视频不工作mp4正在浏览器中使用PHP脚本

时间:2014-05-13 07:39:56

标签: php video browser

我获取视频文件并转换为字符串然后通过使用str_split转换后的字符串转换为array.please请参阅详细信息的代码。对于mp4它的工作但是当我将标题更改为video / 3gpp然后脚本下载。

<?php

$mime_type = "video/3gpp";


$file = "/home/welcome/Videos/abc.3gp";


header("Content-type: $mime_type");

rangeDownload($file);

function rangeDownload($file) {


    $fp = file_get_contents($file, 'r');
    $a = str_split($fp, 5000);
    $size = filesize($file);
    $length = $size;           // Content length
    $start = 0;               // Start byte
    $end = $size - 1;       // End byte

    header("Accept-Ranges: 0-$length");

    if (isset($_SERVER['HTTP_RANGE'])) {

        $c_start = $start;
        $c_end = $end;
        list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);


        if (strpos($range, ',') !== false) {

            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header("Content-Range: bytes $start-$end/$size");
            // (?) Echo some info to the client?
            exit;
        }
        if ($range0 == '-') {
            $c_start = $size - substr($range, 1);
        } else {

            $range = explode('-', $range);
            $c_start = $range[0];
            $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
        }
        $c_end = ($c_end > $end) ? $end : $c_end;
        if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {

            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            header("Content-Range: bytes $start-$end/$size");
            exit;
        }
        $start = $c_start;
        $end = $c_end;
        $length = $end - $start + 1;
        header('HTTP/1.1 206 Partial Content');
    }
    // Notify the client the byte range we'll be outputting
    header("Content-Range: bytes $start-$end/$size");
    header("Content-Length: $length");

    foreach ($a as $k) {
        set_time_limit(0);
        echo $k;
        flush();
    }
}

?>

0 个答案:

没有答案