是否可以使用下载属性强制下载?

问题描述 投票:2回答:1

我知道如何使用download属性强制下载,但我想做一些不同的事情。

<a href="filename.mp4" download=""><img src="download.png"></a>

这是download属性,它可以正常工作,但我想使用meta标签下载,如下所示:

<meta http-equiv="refresh" content="5; url=uploads/<?php echo $_POST["filename"]; ?>"> Please wait while your file start downloading.

它与zipfile,rar等扩展工作得很好。但是当我尝试使用mp4时,它会在浏览器中打开文件而不是强行下载。

php jquery html mysql
1个回答
0
投票

我改变了一些事情。先生,我认为它可以帮到你:第一页代码:

<?php $file = $_POST["filename"]; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="refresh" content="5; url=hello.php?file=<?php echo $file; ?>">

    <title>Document</title>
</head>
<body>

</body>
</html>

然后我创建一个hello.php文件,它包含:

<?php
$file = 'uploads/' . $_GET['file'];

if( !file_exists($file) ) die("File not found");

header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("Content-Length: " . filesize($file));
header('Content-type: vedio/mp4');

readfile($file);
?>

该过程自动下载文件。

© www.soinside.com 2019 - 2024. All rights reserved.