文件删除

This commit is contained in:
2025-09-10 14:33:12 +08:00
parent e2088cc82d
commit e59a690c31
5 changed files with 122 additions and 16 deletions
+19 -8
View File
@@ -134,26 +134,37 @@ class UploadedFilesService
];
}
/**
* 获取文件
*
* @param string $path
* @return bool|\Illuminate\Database\Eloquent\Model
*/
public function getFile(array $where)
{
$file = $this->logicShow(['where' => $where]);
if (!$file) {
return false;
}
return $file;
}
/**
* 删除文件
*
*
* @param int $fileId
* @return bool
*/
public function deleteFile(int $fileId): bool
{
$file = $this->logicShow(['where' => ['id' => $fileId]]);
if (!$file) {
return false;
}
// 删除物理文件
$fullPath = public_path() . $file->file_path;
if (file_exists($fullPath)) {
unlink($fullPath);
}
// 删除数据库记录
return $this->logicDeleteBy(['where' => ['id' => $fileId]]);
}