(五)yii自带的下载功能挺好用的

来源:互联网 发布:手游推荐软件 编辑:程序博客网 时间:2024/04/30 20:13
    /*     * 下载     */    public function actionDownload($id){        if ( isset($_GET['id']) ) {            $model = new Model();//你的model            $result = $model->find(array(                'select' => array('字段1', '字段2'),                'condition' => 'id=:id',//条件                'params'    => array(':id' => $id)                ));            if (!$result) {                throw new CHttpException(404, '文件不存在!');            }            else {                // 服务器端文件的路径                 $fontArr  = explode('/', $result->url);                $fileName = end($fontArr); //得到文件名字                if (file_exists($result->url)){                     //发送两个参数一个是名称上面已经处理好,也可以改成你要的,后面是文件路径                    yii::app ()->request->sendFile ($fileName,  file_get_contents ($result->url));                }             }        }    }    如果你不需要查数据库的话直接做参数传递就好了    yii::app ()->request->sendFile (文件名,  file_get_contents (文件路径));

0 0
原创粉丝点击