public function actionFile($id) { $id = (int) $id; $model = IssueFile::model()->findByPk($id); if (!$model) { throw new CHttpException(404, Yii::t('site', 'Page not found')); } $available_mime = Yii::app()->params['mime_fileview']; $available_mime_microsoft = Yii::app()->params['mime_fileview_microsoft']; $filename = $model->filename; $realname = $model->realname; $uploadPath = $model->issue->getFileFolder(); if (file_exists($uploadPath . $filename)) { $type = CFileHelper::getMimeType($uploadPath . $filename); // get yii framework mime if (in_array($type, $available_mime) || in_array($type, $available_mime_microsoft)) { //.. get the content of the requested file $content = file_get_contents($uploadPath . $filename); //.. send appropriate headers header('Content-Type:' . $type); header("Content-Length: " . filesize($uploadPath . $filename)); header('Content-Disposition: inline; filename="' . $realname . '"'); header('Content-Transfer-Encoding: binary'); header('Accept-Ranges: bytes'); echo $content; exit; } else { Yii::app()->getRequest()->sendFile($realname, file_get_contents($uploadPath . $filename)); } } else { throw new CHttpException(404, Yii::t('site', 'Page not found')); } }
public function actionDeleteFile($id) { if (IssueFile::model()->deleteByPk($id)) { echo "Ajax Success"; Yii::app()->end(); } }