/*
* 下载
*/
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教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号