如何解决 File not found at path:... 重命名文件时? (laravel)

How can I solve File not found at path:... when rename file? (laravel)

我从这里看到:

我这样试:

$destination_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $product->photo;

$new_file_name = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $new_file_name;

// dd($destination_path, $new_file_name);

Storage::move($destination_path, $new_file_name);

存在错误:

[League\Flysystem\FileNotFoundException] File not found at path: C:/xampp/htdocs/myshop/public/img/products/147/Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

如果我 dd($destination_path, $new_file_name), 结果:

C:\xampp\htdocs\myshop\public\img\products7\Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

C:\xampp\htdocs\myshop\public\img\products77-hazard-chelsea.png

我尝试检查文件夹 147 中的 Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png,该文件存在

为什么会出现错误?

更新 :

我找到了解决方案。我这样使用 php 脚本:

rename($destination_path, $new_file_name);。有效

存储使用C:/xampp/htdocs/myshop/storage/app
但您的数据存储在 public 路径

您可以使用 \Storage::exists($path);

$destination_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $product->photo;

$new_file_name = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $new_file_name;

// dd($destination_path, $new_file_name);
if(\Storage::exists($destination_path)){
    Storage::move($destination_path, $new_file_name);
}