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}");
 }
 /**
  * @return AppAttachment[]
  * @throws \Exception
  */
 public function getFiles()
 {
     $fileQuery = AppAttachment::find()->where(['item_id' => $this->owner->id, 'model' => $this->getModule()->getShortClass($this->owner)]);
     $fileQuery->orderBy(['id' => SORT_ASC]);
     return $fileQuery->all();
 }
Beispiel #3
0
 public function detachFile($id)
 {
     $file = AppAttachment::findOne(['id' => $id]);
     $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type;
     unlink($filePath);
     $file->delete();
 }