2012-04-04 67 views
0

我想要yii框架中的下载按钮 当我点击那个按钮然后新弹出窗口将打开要求打开或保存.. plz帮助我sooon 非常感谢你....yii代码中的下载按钮

我已经试过这样的,但它会在新窗口中只有我不能下载打开...

echo "<b>".$data->job_related_file->srvr_name."</b> (".CHtml::link("<b>Download</b>",$downloadLink,array('target'=>'_blank')).")"; 

enter image description here

当我点击字按钮,然后看到这个图像

enter image description here

+1

质量好图片...如果我不在Linux上,我会tr y并单击该确定按钮。 – 2012-08-16 22:34:49

回答

1

您需要添加 //动作控制器

function actionDownload($name){ 
    $filecontent=file_get_contents('path_to_file'.$name); 
    header("Content-Type: text/plain"); 
    header("Content-disposition: attachment; filename=$name"); 
    header("Pragma: no-cache"); 
    echo $filecontent; 
    exit; 
} 

//下载链接鉴于

echo "<b>". 
    $data->job_related_file->srvr_name."</b> (". 
    CHtml::link("Download","CONTROLLER/download/$filename", 
     array('class'=>'donwload_link') 
    ) 
    .")"; 

我还没有测试,虽然它,让我知道这是否工作

+0

target = _blank表示它在新窗口中打开?@sakhunzai – User1988 2012-04-04 12:51:34

+0

对不起,我将删除它,你不需要目标空白的东西。您期望的弹出窗口将由BROWSER提供,您不需要它 – sakhunzai 2012-04-04 12:56:04

+0

实际上您从PHP发送的标题将执行此操作(弹出保存为或查看) – sakhunzai 2012-04-04 12:58:14