/* * 下载 */ 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 (文件路径));
以上就介绍了(五)yii自带的上传功能挺好用的,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。