0

I want the button of download in yii framework when i click on that button then new pop up window will open for to ask to open or save .. plz help me sooon thank you so much....

I have tried like this but it will open in new window only i cant download...

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

enter image description here

When I click on word button then see this image

enter image description here

4

1 回答 1

1

您需要在控制器中添加 //action

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')
   )
  .")";

我还没有测试过,让我知道这是否有效

于 2012-04-04T12:50:29.553 回答