在CGrid视图Yii中创建下载链接


Create download link in CGrid view Yii

我是Yii的新手。我有一个表单,用户可以通过它提交一些信息,包括文件。文件存储在我的图像目录中。。。现在我想要的是在我的VIEW中创建一个链接来下载上传的文件。查看代码

    <b><?php echo CHtml::encode($data->getAttributeLabel('Resume')); ?>:</b>
        <? echo CHtml::link($data,array('displaySavedImage','id'=>$model->id)); ?>
controller
public function actionDisplaySavedImage()
{
    $model=$this->loadModel($_GET['id']);
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Content-Transfer-Encoding: binary');
    header('Content-length: '.$model->file_size);
    header('Content-Type: '.$model->file_type);
    header('Content-Disposition: attachment; filename='.$model->file_name);
        echo $model->file_content;
}

使用Yii::app()->getRequest()->sendFile("文件名",file_get_contents("图像路径"));

http://www.yiiframework.com/doc/api/1.1/CHttpRequest#sendFile-详细