I am complete noob, so please forgive my ignorance.
I have searched in the yii documentation, the yii cookbook, and online for a tutorial that will show me how to do this, but I have yet to find a solution. I'm sure it's pretty simple, I would appreciate any help.
I have a facility whereby the admin user can upload files to the server. I now need to make a link where that file is available for download by any user using CHttpRequest's sendFile() function. The link will be located in the side menu (using 'views/layouts/column2.php'.)
The code on my view:
$link = '<div id="schedule_download"></div>'; echo CHtml::link($link ,array('/admin/download'));
The code in my controller:
public function actionDownload() { //find the last uploaded file $criteria=new CDbCriteria $criteria->order = 'admin_id DESC'; $criteria->limit = '1'; $downloads = Admin::model()->findAll($criteria); foreach ($downloads as $download): $path = Yii::app()->request->hostInfo . Yii::app()->request->baseURL . '/uploads/schedule/' . $download->schedule; endforeach; if(file_exists($path)) { return Yii::app()->getRequest()->sendFile('myfile.pdf', @file_get_contents($path)); } }
When I click on the link it takes me to a blank page.
I would merely like the file download dialogue to appear and no other page re-directs.
Please can somebody show me where I am going wrong, or provide a link to a tutorial that will explain this process better. Thanks
