激活视频文件的另存为或打开弹出框

Activate save-as or open pop-up box for video files

在我的 .htaccess 中,我是否设法激活了一个带有另存为和打开文件下载选项的弹出框,这些文件是图像、jpg、jpeg、png 等。这非常有效。

这里是代码:

<IfModule mod_headers.c>
    <FilesMatch "\.jpg$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.jpeg$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.png$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.ogv$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.mov$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.avi$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.mp4$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>
</IfModule>

现在我想为视频文件(ogv、avi、mp4 等)提供相同的功能,并且我以相同的方式添加了代码,但它不适用于视频文件,如何制作此解决方案工作?

您可以使用AddType强制下载:

AddType application/octet-stream .ogv
AddType application/octet-stream .avi
AddType application/octet-stream .mp4

或者,您可以使用此方法,并合并您已经完成的其他文件类型:

<FilesMatch "\.(jpe?g|png|ogv|mov|avi|mp4)$" >
    ForceType application/octet-stream
    Header add Content-Disposition "attachment"
</FilesMatch>

这也是您可以尝试的选项:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(jpe?g|png|ogv|mov|avi|mp4)$ - [T=application/octet-stream]

关于 Firefox: FF 似乎需要设置文件名。这是我能想到的最好的方法 - 它似乎完美地工作:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+).(jpe?g|png|ogv|mov|avi|mp4)$ - [env=filename:.]

<FilesMatch "\.(jpe?g|png|ogv|mov|avi|mp4)$" >
    ForceType application/octet-stream
    Header add Content-Disposition "attachment; filename=%{filename}e"
</FilesMatch>

在这里,我们正在检查请求是否针对现有文件,以及文件是否以特定扩展名结尾。如果是这样,设置一个名为 filename 的环境变量,并将其传递给 Header add。很神奇,真的。 Firefox 对其他一些事情也非常严格 - 所以很高兴知道这一点。