强制用户使用PHP下载文件 [英] Force user to download file in PHP

查看:126
本文介绍了强制用户使用PHP下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

强制使用PHP下载文件


当我们需要强制用户下载文件时,我们使用带有多个参数/选项的标题。如果我使用

 标题(location:test.xlsx); 

这是工作:)使用这个快捷方式有什么缺点吗?

解决方案

这种方法有几个缺点: p>如果文件是浏览器可以读取的文件,它将不会被下载(例如 .txt .pdf .html .jpg .png .gif 以及更多),但只需在浏览器中显示

  • 用户可直接链接到文件。很多时候,你不需要这个,因为他们可以把这个链接给其他人,所以...


    1. 它会花费你更多的带宽

    2. 如果它是图片,它不能用于私人文件




  • 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:

    1. 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 browser

    2. Users get the direct link to the file. Quite often, you don't want this because they can give this link to others, so...

      1. it will cost you more bandwidth
      2. it can't be used for private files
      3. if it's an image, they can hotlink to it

    这篇关于强制用户使用PHP下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆