gpt4 book ai didi

php - 使用php从保存在mysql中的路径下载视频

转载 作者:行者123 更新时间:2023-11-29 12:35:59 25 4
gpt4 key购买 nike

我正在使用保存在数据库中的目录路径。我如何从路径下载。我的代码是。

        if(isset($_POST['download'])) {

$id = $_GET['id'];
$query = "SELECT url_video FROM website WHERE id = '$id'";
$result = mysql_query($query); $rowss = mysql_fetch_assoc($query);
$name2 = $rowss['url_video'];

header("Accept-Ranges: bytes");
header("Keep-Alive: timeout=15, max=100");
header('Content-Disposition: attachment; filename='.$name2);
header("Content-type: video/mp4");
//header("Content-Transfer-Encoding: binary");
header( "Content-Description: File Transfer");

exit;
}

?>

最佳答案

设置下载 header 后,您需要输出/回显文件的内容。

还有以下内容

header('Content-Disposition: attachment; filename='.$name2);

应该是

header('Content-Disposition: attachment; filename='.$file_name_not_full_path);

header('Content-Disposition: attachment; filename=downloadedvideo.mpg');

完整代码(我假设您有一个名为 video_path 的列,用于存储服务器上文件的路径:

if(isset($_POST['download'])) {

$id = $_GET['id'];
query = "SELECT url_video, video_path FROM website WHERE id = '$id'";
$result = mysql_query($query);
$rowss = mysql_fetch_assoc($query);

header("Accept-Ranges: bytes");
header("Keep-Alive: timeout=15, max=100");
header('Content-Disposition: attachment; filename='.$rowss['url_video']);
header("Content-type: video/mp4");
header("Content-Transfer-Encoding: binary");
header( "Content-Description: File Transfer");

readfile($rowss['video_path']);
}

最后评论后的新代码版本:

if(isset($_POST['download'])) {

$id = $_GET['id'];
query = "SELECT url_video FROM website WHERE id = '$id'";
$result = mysql_query($query);
$rowss = mysql_fetch_assoc($query);

header("Location: ".$rowss['url_video']);
exit();
}

关于php - 使用php从保存在mysql中的路径下载视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26789290/

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