gpt4 book ai didi

php - 在 chrome 中加载视频时出现 ERR_CONTENT_LENGTH_MISMATCH

转载 作者:可可西里 更新时间:2023-10-31 23:37:06 25 4
gpt4 key购买 nike

所以我在播放某些视频时遇到此错误。当 Chrome 完全下载视频时,它会停止播放并出现此错误。此外,请求的状态从 206 更改为(失败),然后 Chrome 发送了一些其他带有 Range:bytes=2990775- 的请求,服务器响应为:

Accept-Ranges:bytes
Cache-Control:private
Connection:keep-alive
Content-Disposition:attachment; filename="About The Author.mp4"
Content-Length:0
Content-Range:bytes 2990775-2990775/2990776
Content-Transfer-Encoding:binary
Content-Type:video/mp4
Date:Tue, 14 Feb 2017 13:46:24 GMT
Last-Modified:Wed, 08 Feb 2017 05:43:27 GMT
Pragma:public
Server:Apache/2
Vary:User-Agent
X-Powered-By:PHP/5.4.45

我在同一台服务器上有另一个网站,在那里工作正常。

这是我的 PHP 代码:

        $filesize = filesize($resource->path);

$matches = explode("-", substr($_SERVER['HTTP_RANGE'],6));
if (empty($matches[1]))
{
$matches[1] = $filesize - 1;
}

$offset = intval($matches[0]);
$length = intval($matches[1]) - $offset;

$file = fopen($resource->path, 'r');

fseek($file, $offset);

$data = fread($file, $length);
fclose($file);

header('HTTP/1.1 206 Partial Content');
header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize);

header('Pragma: public');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($resource->path)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: ' . $mime);
header('Content-Length: ' . ($length + 1));
header('Content-Disposition: attachment; filename="' . $resource->filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');

print($data);

抱歉我的英语不好。

最佳答案

我发现了问题。

我将 $data = fread($file, $length); 更改为 $data = fread($file, $length + 1);

我不知道为什么请求的长度应该加一,但它解决了问题。

关于php - 在 chrome 中加载视频时出现 ERR_CONTENT_LENGTH_MISMATCH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42227944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com