PHP:打开一个文件下载对话框 [英] PHP: open a file download dialog
问题描述
我有一个在Amazon S3中托管的MPEG文件(.mpg),我想链接到我拥有的一个页面,因此用户将能够从该页面下载它。
我在我的页面上有一个链接:
bla bla / p>
当我右键单击它并选择另存目标时,该文件的链接工作正常,但是当我点击它时,我希望它也能工作。它会打开一个文件下载对话框,现在,左键单击将直接进入一个有视频直接播放的页面(在FireFox中),或者只是不会加载(在Internet Explorer中)。
我在PHP中工作,为什么会发生这种情况?
文件在一个下载PHP脚本中发送相应的 Content-Disposition
标题,告诉浏览器将其视为下载内容而不是内容项目。
$ b
例如:
header(Content-Disposition:attachment; filename = yourfilenamehere.ext> ;);
http://support.microsoft.com/kb/260519
I have an MPEG file (.mpg) hosted in Amazon S3, that I want to link to a page I have, so the user will be able to download it from the page. I have in my page a link: bla bla"
The link to the file works when I right-click it and choose "Save Target As" , but I would like it to work also when I left click it, and that it will open a file download dialog. right now, a left click will direct to a page that has the video directly played in it (in FireFox) or just won't load (in Internet Explorer).
I am working in PHP, why does this happen?
You probably want to wrap the file within a "download" PHP script that sends the appropriate Content-Disposition
header telling the browser to treat it as a download instead of a content item.
For instance:
header("Content-Disposition: attachment; filename=yourfilenamehere.ext>");
http://support.microsoft.com/kb/260519
这篇关于PHP:打开一个文件下载对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!