文件删除
This commit is contained in:
@@ -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]]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user