public function actionDownload() { if (!Yii::$app->user->can("admin")) { throw new HttpException(403, 'You are not allowed to perform this action.'); } $dataProvider = new ActiveDataProvider(['query' => DownloadLog::find()]); return $this->render('download', ['dataProvider' => $dataProvider]); }
public function actionFile($id) { $model = File::findOne(['id' => $id]); if ($model === NULL) { throw new HttpException(403, 'You are not allowed to perform this action.'); } if (file_exists($model->filepath)) { //Check to see if the user has permissions $ffgs = FileFileGroup::find()->where(['file_id' => $id])->all(); $ffgs_list = []; $found = 0; foreach ($ffgs as $f) { $ufg = UserFileGroup::find()->where(['file_group_id' => $f->group_id, 'user_id' => \Yii::$app->user->identity->id]); if ($ufg !== NULL) { $found = 1; break; } } if ($found == 1) { $user = User::findOne(['id' => \Yii::$app->user->identity->id]); $dl = new DownloadLog(); $dl->username = $user->username; $dl->email = $user->email; $dl->filepath = $model->filepath; $dl->download_time = date("Y-m-d H:i:s"); $dl->filename = $model->filename; $dl->user_id = $user->id; $dl->save(); return \Yii::$app->response->sendFile($model->filepath); } else { throw new HttpException(403, 'You are not allowed to perform this action.'); } } else { return $this->redirect(['/site/error']); } }
public function downloadLog($fileId) { $log = new DownloadLog(); $log->d_log_id = md5($fileId . $_SESSION['user']['user_id'] . date('Y-m-d H:i:s')); $log->user_id = $_SESSION['user']['user_id']; $log->file_id = $fileId; $log->download_date = date('Y-m-d H:i:s'); if ($log->save()) { return 'success'; } else { return $log->errors; } }