【问题标题】:Is it possible to force download using download attribute?是否可以使用下载属性强制下载?
【发布时间】:2017-08-23 03:09:27
【问题描述】:

我知道如何使用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 时,它会在浏览器中打开文件而不是强制下载。

【问题讨论】:

  • @SatishSaini 不,这是不同的家伙!我使用 meta http-equiv 刷新在 5 秒后下载
  • 是的,它认为它不同
  • @Jayanta 反正我可以在 meta http-enquiv 中使用 ahref 下载属性吗?
  • 先生,请稍等片刻

标签: php jquery html mysql


【解决方案1】:

我改变了一些东西。先生,我认为它可以帮助你: 第一页代码:

<?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);
?>

进程自动下载文件。

【讨论】:

  • 它对我不起作用。如果我想这样使用它怎么办: 你能告诉我你为什么使用 $_POST文件名,然后是 $_GET 方法?
  • 这对我有用。你只需要使用 Content-Disposition: attachment; 到另一个文件头
  • 我发送文件名并在 hello.php 文件中通过 $_GET 获取文件名
  • 先生你能理解吗
  • 你只需要新建一个php文件。并把标题设置
猜你喜欢
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
  • 1970-01-01
  • 2013-02-19
  • 1970-01-01
相关资源
最近更新 更多