public function detachFile($id) { /** @var File $file */ $file = File::findOne(['id' => $id]); if (empty($file)) { return false; } $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type; // this is the important part of the override. // the original methods doesn't check for file_exists to be return file_exists($filePath) ? unlink($filePath) && $file->delete() : $file->delete(); }
public function detachFile($id) { $file = File::findOne(['id' => $id]); $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type; unlink($filePath); $file->delete(); }
public function actionDownload($id) { $file = File::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}"); }