• 技术文章 >php教程 >php手册

    解析PHP实现下载文件的两种方法

    2016-06-13 11:43:16原创621
    方法一:

    复制代码 代码如下:


    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($filepath));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0′);
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0′);
    header('Pragma: public');
    header('Content-Length: ' . filesize($filepath));
    readfile($file_path);


    方法二:

    复制代码 代码如下:


    $fileinfo = pathinfo($filename);
    header('Content-type: application/x-'.$fileinfo['extension']);
    header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
    header('Content-Length: '.filesize($filename));
    readfile($thefile);
    exit();

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:PHP调用MsSQL Server 2012存储过程获取多结果集(包含output参数)的详解 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • 建立文件交换功能的脚本(二)• PHP教程.应用实例2 • 对MVC的理解,MVC理解• 新浪SAE搭建PHP项目教程,新浪sae搭建php• 程序员吃自助餐后的反思
    1/1

    PHP中文网