即使下载链接重定向到另一个,也要设置下载文件的名称 [英] Set name of the download file even if download link redirect to another
问题描述
我拥有一个 http://example.com/1.html 网页,并且我拥有它链接 http://example.com/1.mp4
< a href =http://example.com/1.mp4>下载< / a>
重定向到另一个链接 https://example.com/videoplayback?....
播放.mp4文件。为了在不重定向的情况下下载文件,我使用下载属性
< a href =http://example.com /1.mp4下载>下载< / a>
为了给文件设置一个名字,我给下载属性设置一个值
< a href =http://example.com/1.mp4download =S1E1.mp4>下载< / A>
现在,当我点击链接时,文件应该以名称S1E1.mp4开始下载,但因为链接重定向到另一个链接文件名是videoplayback。
那么我怎样才能将这个文件的名字设置为S1E1.mp4。
感谢您的一切。如果我的问题不明确,请发表评论,我将对其进行编辑。 解决方案
真正的问题是:为什么你重定向?我想你使用的是htaccess?然后使用正常的重写,而不是重定向。
编辑:
您的PHP脚本至少应该提供每个头文件名:
header('Content-type:-whatever type this is-');
header('Content-Disposition:attachment; filename =My-Super-Video.mp4');
I have a page http://example.com/1.html and on it I have a link http://example.com/1.mp4
<a href="http://example.com/1.mp4">Download</a>
which redirect to another link https://example.com/videoplayback?.... which plays the .mp4 file. In order to download the file without redirect I use the download attribute
<a href="http://example.com/1.mp4" download>Download</a>
and in order to set a name to the file I set a value to the download attribute
<a href="http://example.com/1.mp4" download="S1E1.mp4">Download</a>
Now when I click the link the file should start downloading with the name S1E1.mp4 but because the link redirect to another link the file name is "videoplayback". So how can I set the name of this file to be "S1E1.mp4". Thanks for everything. If my question is not clear leave a comment and I'll edit it.
The real Question is: Why do you redirect? I guess you're using htaccess? Then use a normal rewrite, not a redirect.
Edit:
Your PHP-Script should at least provide a Filename per header:
header('Content-type: -whatever type this is-');
header('Content-Disposition: attachment; filename="My-Super-Video.mp4"');
这篇关于即使下载链接重定向到另一个,也要设置下载文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!