Does Yii have any built-in functionality to force a "file/save as" dialog when clicking on a file URL?
Does Yii have any built-in functionality to force a "file/save as" dialog when clicking on a file URL?
Anyone able to advise?
The simplest is to create a action to download this file.
I thing there are ‘download files’ classes at http://www.phpclasses.org/
http://www.yiiframework.com/doc/api/1.0.11/CHttpRequest#sendFile-detail in combination with a controller action
Can you give me exaple please, I have no idea how to do this.
The first class that I have in mind is this and codeigniter simiral class.
I thing you can get the code of this class and use it as extension.
Here is an example. Call it with yourdomain.tld/index.php?r=test/download
The file lies in the folder "download" under your document root.
Controller Test:
/**
* Download of the file
*/
public function actionDownload()
{
$file = '/download/document.pdf';
return Yii::app()->getRequest()->sendFile(basename($file), @file_get_contents(Yii::app()->getBasePath().'/..'.$file));
}
No actually I want to create a link to the file itself, e.g. document.docx
In IE by default it opens up the document within the browser window. But I have seem some sites whereby you are always given the option to save the file even if it is a direct link to the file.
I don’t suppose I could add .htaccess rules to do this? The only file types I am dealing with are .pdf and .doc