Home > Backend Development > PHP Tutorial > (5) The upload function that comes with yii is very easy to use.

(5) The upload function that comes with yii is very easy to use.

WBOY
Release: 2016-08-08 09:27:54
Original
1369 people have browsed it
    /*
     * 下载
     */
    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 (文件路径));
Copy after login

The above has introduced (5) Yii’s built-in upload function is very easy to use, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template