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}"); }
public function detachFile($id) { $file = AppAttachment::findOne(['id' => $id]); $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type; unlink($filePath); $file->delete(); }