强制用户使用PHP下载文件 [英] Force user to download file in PHP
问题描述
可能存在重复:
强制使用PHP下载文件
当我们需要强制用户下载文件时,我们使用带有多个参数/选项的标题。如果我使用
标题(location:test.xlsx);
这是工作:)使用这个快捷方式有什么缺点吗?
这种方法有几个缺点: p>如果文件是浏览器可以读取的文件,它将不会被下载(例如 用户可直接链接到文件。很多时候,你不需要这个,因为他们可以把这个链接给其他人,所以... .txt
, .pdf
, .html
, .jpg
, .png
, .gif
以及更多),但只需在浏览器中显示
Possible Duplicate:
Forcing to download a file using PHP
When we need to force user to download a file, we use header with several parameters/options. What if I use
header("location:test.xlsx");
This is working :) Is there any drawback of using this shortcut ?
There are a few disadvantages to this method:
If the file is one the browser can read, it won't be downloaded (like
.txt
,.pdf
,.html
,.jpg
,.png
,.gif
and more), but simply be shown within the browserUsers get the direct link to the file. Quite often, you don't want this because they can give this link to others, so...
- it will cost you more bandwidth
- it can't be used for private files
- if it's an image, they can hotlink to it
这篇关于强制用户使用PHP下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!