0

我在<a href>指向视频文件 (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;
?>
4

1 回答 1

4

Content-Disposition标题设置为attachment. 例如:

Content-Disposition: attachment; filename=lolcats42.mp4
于 2012-02-06T18:17:43.237 回答