修改名字

This commit is contained in:
Edward Yang 2022-07-13 16:58:43 +08:00
parent ef1b14fe54
commit 174b8f3438
2 changed files with 6 additions and 2 deletions

View File

@ -50,7 +50,7 @@ class FileManagerController extends Controller
$originPath = $request->get('origin_name');
$newPath = $request->get('new_name');
(new FileManagerService)->updateName($originPath, $newPath);
return json_success('删除成功');
return json_success('修改成功');
}

View File

@ -116,10 +116,14 @@ class FileManagerService
public function updateName($originPath, $newPath)
{
$originPath = public_path("catalog/{$originPath}");
$newPath = public_path("catalog/{$newPath}");
if (!is_dir($originPath) || !file_exists($originPath)) {
throw new \Exception('原始文件或者文件夹无效');
}
$originBase = dirname($originPath);
$newPath = $originBase . '/' . $newPath;
if ($originPath == $newPath) {
return;
}
@rename($originPath, $newPath);
}