无需右键单击即可下载文件

发布于 2025-01-03 04:05:06 字数 675 浏览 4 评论 0原文

我的页面上有一个指向视频文件 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罗罗贝儿 2025-01-10 04:05:06

Content-Disposition 标头 设置为 attachment< /代码>。例如:

Content-Disposition: attachment; filename=lolcats42.mp4

Set the Content-Disposition header to attachment. For example:

Content-Disposition: attachment; filename=lolcats42.mp4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文