gpt4 book ai didi

php - 在 Chrome 的 HTML5 视频标签中通过 php 播放 mp4 文件?

转载 作者:行者123 更新时间:2023-12-03 23:23:41 25 4
gpt4 key购买 nike

我有 mp4 文件的问题。 Html5 Video Tag 可以用直接链接播放,但不能用 PHP Header 播放(Mp3 与 PHP Header 一起工作得很好)。我已经在 Stack 中尝试了几乎所有的解决方案,但仍然没有解决我的问题:(

听到是我的代码:

PHP mp4.php

    error_reporting(0);

$local_file = 'z.mp4';//'b.mp3';
$download_file = 'out.mp4';
// send headers
header('Cache-control: private');
header('Content-Type: video/mp4');
header('Content-Length: '.filesize($local_file));
header('Content-Disposition: filename='.$download_file);
header('Accept-Ranges: bytes');
header("Content-Transfer-Encoding: binary");
readfile($local_file);

HTML
     <video controls="" autoplay="" name="media">
<source src="http://localhost/videos/mp4.php" type="video/mp4">
</video>

我不知道为什么:(请帮助我。

谢谢,

最佳答案

好的!我已经解决了我的问题 :) 希望这会帮助任何和我有同样问题的人

只需使用该代码:

$file = 'local_file';
$newfile = 'outFile';

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($newfile));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}

关于php - 在 Chrome 的 HTML5 视频标签中通过 php 播放 mp4 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24596450/

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