コード例 #1
0
 public function actionDownload($id)
 {
     $file = AppAttachment::findOne(['id' => $id]);
     $filePath = $this->getModule()->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type;
     return \Yii::$app->response->sendFile($filePath, "{$file->name}.{$file->type}");
 }
コード例 #2
0
ファイル: Module.php プロジェクト: dlds/yii2-attachments
 public function detachFile($id)
 {
     $file = AppAttachment::findOne(['id' => $id]);
     $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type;
     unlink($filePath);
     $file->delete();
 }