简体   繁体   English

无法读取大于2GB的文件

[英]Unable to read files which are greater than 2GB

I am using this below code to stream a movie on my localhost. 我正在使用以下代码在本地主机上流电影。 The movie which is lesser then 2GB works fine but when it comes to movie greater than 2gb then the movie doesn't play. 小于2GB的电影可以正常工作,但是对于大于2GB的电影,则无法播放。

Please help me what should I do to read larger files. 请帮助我阅读更大的文件该怎么办。

This is the code I am using for streaming movie 这是我用于流电影的代码

<?php

//Determine file path according to extension
if (!isset($_GET['ext']) || $_GET['ext'] == 'mp4') {
    $path ='movies/'.$_GET['movie'];
}


$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($path);
header('Content-Type: ' . $mime);

$size = filesize($path);


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


    list($specifier, $value) = explode('=', $_SERVER['HTTP_RANGE']);
    if ($specifier != 'bytes') {
        header('HTTP/1.1 400 Bad Request');
        return;
    }


    list($from, $to) = explode('-', $value);
    if (!$to) {
        $to = $size - 1;
    }


    $fp = fopen($path, 'rb');
    if (!$fp) {
        header('HTTP/1.1 500 Internal Server Error');
        return;
    }


    header('HTTP/1.1 206 Partial Content');
    header('Accept-Ranges: bytes');


    header('Content-Length: ' . ($to - $from));


    header("Content-Range: bytes {$from}-{$to}/{$size}");


    fseek($fp, $from);


    while(true){

        if(ftell($fp) >= $to){
            break;
        }


        echo fread($fp, 8192);

        // Flush do buffer
        ob_flush();
        flush();
    }
}
else {

    header('Content-Length: ' . $size);


    readfile($path);
}

I have hosted the files on localhost using xammpp as a server. 我已经使用xammpp作为服务器将文件托管在localhost上。

This could have different reasons. 这可能有不同的原因。

fopen() reads a file into your RAM. fopen()将文件读入RAM。 So the limitation seems to come from there. 因此,限制似乎来自那里。

First, make sure you have min 4GB installed in your system. 首先,请确保您的系统中至少安装了4GB。 If you need more also make sure you dont use a Win 32-Bit system since this only supports up to 4GB ram. 如果还需要更多,请确保不要使用Win 32位系统,因为该系统仅支持最高4GB的RAM。

Then you can try to increase the memory_limit of PHP. 然后,您可以尝试增加PHP的memory_limit Open the xampp/php/php.ini file and change the memory_limit to what ever you need OR set the ini value directly in your php file like this 打开xampp / php / php.ini文件,将memory_limit更改为您需要的值,或者像这样直接在您的php文件中设置ini值

ini_set(”memory_limit”,”16M”);

Hope this helps. 希望这可以帮助。 For a more specific answer it would be helpful if you have any error message. 对于更具体的答案,如果您有任何错误消息,将很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM