无需右键单击即可下载文件
我的页面上有一个指向视频文件 (mp4) 的 链接。当访问者单击链接时,视频文件将在浏览器窗口中打开。
如果您想下载该文件,则必须“右键单击”,然后“将链接另存为...”
我希望这样只需单击一次即可下载文件(这样我就不必右键单击) 。
编辑:这里有什么问题?
<?php
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename=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;
?>
I have an <a href>
link on a page that points to a video file (mp4). When the visitor clicks the link, the video file opens in the browser window.
If you want to download the file, you have to "right click", and then "save link as..."
I want that so that on a single click file will download (so that I don't have to right click).
edit: What's the problem here?
<?php
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename=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;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
Content-Disposition
标头 设置为attachment< /代码>。例如:
Set the
Content-Disposition
header toattachment
. For example: