简体   繁体   中英

how to make download link in yii?

I want to make a download link for files stored in my webapp directory, so when the user click a link the file should be downloaded, here is my code:

 $src= Yii::app()->request->baseUrl;
 $url2 = $src."/CVs/resumes/".$m->idJob."-".$m->cv;
 $url = Yii::app()->getRequest()->sendFile( $m->cv , file_get_contents( $url2 ) );
 echo"<tr><td style='border:4px solid;border-color: black;text-align: center;'>".
 CHtml::link($m->fullName, array('submit'=>$url))."</td></tr>";

I got an error that there is no such file or directory, where is the wrong?

Try removing the third line and changing the last line to CHtml::link($m->fullName, $url2)."</td></tr>";

Please, let me know if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM