2012-04-04 47 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