Php 使用_geturl作为视频源
基本上,我有下面的代码,将获得一个基于其id值的视频Php 使用_geturl作为视频源,php,url,video,get,Php,Url,Video,Get,基本上,我有下面的代码,将获得一个基于其id值的视频 <?php if (isset($_GET["id"])) { $id = $_GET["id"]; $video = "vid" . $id; echo "<video controls><source src='{$video}' type='video/mp4'></video>"; } else { echo "File not found."
<?php
if (isset($_GET["id"])) {
$id = $_GET["id"];
$video = "vid" . $id;
echo "<video controls><source src='{$video}' type='video/mp4'></video>";
} else {
echo "File not found.";
}
?>
当您直接嵌入为src时,您需要直接加载视频,因为您的代码添加了这样的输出,使得第二个选项不正确,例如:
direct video的url为:
如果仍要使用video.php?id=555.mp4
,则需要更改php以读取流媒体文件。作为源的URL不是源。它是指向将加载源代码的脚本的链接。它需要指向文件结构中包含视频的位置,而不是将其作为源。因此,您需要在代码中构建结构,并将其回送到标记中
<?php
if (isset($_GET["id"])) {
$id = $_GET["id"];
$video = "vid" . $id;
echo "<video tabindex=\"0\" controls=\"controls\">";
echo "<source src=\"{$video}\" type=\"video/mp4\">";
echo "</video>";
} else {
echo "File not found.";
}
?>
我已经测试了您的代码,但这两种代码都不适用于我(访问您发布的URL,或使用URL作为源代码)
视频播放器同时出现在两个屏幕上,但两个屏幕上都不播放视频 好的,我设法做到了。我刚把第一个代码改成
<?php
$id = $_GET["id"];
$file = "vid" . $id . ".mp4";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
我现在可以在一个iframe中用一个带有?id=555的URL外部链接它,它会将视频文件加载到播放器中。你应该逃逸$\u GET['id']:>@JimL抱歉,我不太明白你说的话,你能修改代码吗?我该怎么做,因为流式传输是我想要的结果。无论如何,要使用id=55流式传输吗?
<?php
if (isset($_GET["id"])) {
$id = $_GET["id"];
$video = "vid" . $id;
echo "<video tabindex=\"0\" controls=\"controls\">";
echo "<source src=\"{$video}\" type=\"video/mp4\">";
echo "</video>";
} else {
echo "File not found.";
}
?>
<?php
$id = $_GET["id"];
$file = "vid" . $id . ".mp4";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>