public function actionDownload($id) { $model = Referensi::model()->findByPk($id); $model->timestamp = new CDbExpression('NOW()'); $filename = "protected/file/" . $model->file; $content = "Content-Disposition: attachment;filename=\"" . $model->file . "\""; header('Content-Type: application/force-download'); header('Cache-Control: max-age=0'); $filecontent = file_get_contents($filename); header($content); echo $filecontent; exit; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Referensi the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Referensi::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }