thinkphp的文件下载实现方式

浏览:17389 发布日期:2013/05/03 分类:技术分享 关键字: 文件下载
public function file_down($id){

        if(empty($_GET['id'])){
            redirect("文件不存在跳转页面");
        }else{//如果要加登录条件,这里可以自己加

           $dl=D('downlist');
                    $map['id'] = array('eq',$_GET['id']);
                    $list=$dl->where($map)->find();

                   if ($list == false) {//文件不存在,可以跳转到其它页面
             header('HTTP/1.0 404 Not Found');
                        header('Location: .');
                    } else {
                          header("Expires: ".gmdate("D, d M Y H:i:s", time() + 3600000)." GMT");
                          header('Content-type:application/octet-stream', true);
                         echo($list["file_zip"]);//file_zip为打包文件字段
                    }

         }

    }
//注:字段file_zip需要使用ZipArchive打包存储
最佳答案
评论( 相关
后面还有条评论,点击查看>>