zoukankan      html  css  js  c++  java
  • think PHP5实现文件下载

    public function download()
        {
            $famlePath = $_GET['resum'];
            $file_dir = ROOT_PATH . 'public' . DS . 'uploads' . '/' . "$famlePath";    // 下载文件存放目录
            
            // 检查文件是否存在
            if (! file_exists($file_dir) ) {
                $this->error('文件未找到');
            }else{
                // 打开文件
                $file1 = fopen($file_dir, "r");
                // 输入文件标签
                Header("Content-type: application/octet-stream");
                Header("Accept-Ranges: bytes");
                Header("Accept-Length:".filesize($file_dir));
                Header("Content-Disposition: attachment;filename=" . $file_dir);
                ob_clean();     // 重点!!!
                flush();        // 重点!!!!可以清除文件中多余的路径名以及解决乱码的问题:
                //输出文件内容
                //读取文件内容并直接输出到浏览器
                echo fread($file1, filesize($file_dir));
                fclose($file1);
                exit();
            }
        }
    ---------------------  
    版权声明:本文为CSDN博主「jartin」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/jartins/article/details/82354372

  • 相关阅读:
    微信·小程序开发工具安装指南及注意事项
    测试
    PC上面的蓝牙的通信(C#)
    关于图片在div中居中问题
    JSONP---跨域请求问题
    关于position的用法
    APICloud自学笔记总结1
    前端html5
    关于图片自适应div大小问题
    亲身经历——大体量公司能为程序员的生涯带来什么帮助?
  • 原文地址:https://www.cnblogs.com/PHP0222wangdong/p/11360618.html
Copyright © 2011-2022 走看看