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

  • 相关阅读:
    linux sed的使用
    linux 服务的操作
    Js apply方法详解,及其apply()方法的妙用
    call()方法和apply()方法
    javascript中的深拷贝和浅拷贝
    移动web适配利器-rem
    js 函数讲解
    try…catch 结构
    Git使用之(pathspec master did not match any file(s) known to git)
    微信小程序使用函数的三种方法
  • 原文地址:https://www.cnblogs.com/PHP0222wangdong/p/11360618.html
Copyright © 2011-2022 走看看