PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    PHP实现文件强制下载

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:如果你不希望txt pdf excel在浏览器上查看的话,强制下载吧
    如果你不希望txt pdf excel在浏览器上查看的话,强制下载吧。
     
    复制代码代码如下:
    1. <?php
    2.     $file_dir = "./";    
    3.     $name = "test.txt";
    4.     $file = fopen($file_dir.$name,"r");
    5.     Header("Content-type: application/octet-stream");
    6.     Header("Accept-Ranges: bytes");
    7.     Header("Accept-Length: ".filesize($file_dir . $name));
    8.     Header("Content-Disposition: attachment; filename=".$name);
    9.     echo fread($file, filesize($file_dir.$name));
    10.     fclose($file);
    11. ?>
    12.  

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-191-1.html
    相关热词搜索: 文件下载