I am using the Yii framework basic and I have the website to allow the admin to upload a text file and I need to download file from my folder, but I am unable to download.
My controller action is
public function actionDownload(){
$url= $_GET["url"];
$path = Yii::getAlias('@webroot') . "/$url";
$file = $path;
if (file_exists($file)) {
Yii::$app->response->sendFile($file);
}
}
my view is
<a href="download?url=download/notes/trIssues5850f5ae5cd6.docx">DOWNLOAD</a>
If I click download it just read the content of the file and display straight in the page. What I want to do is when users click the download link, the download dialog will pop up or the file will be automatically downloaded, rather than display the content.