我从这里看到:rename a directory or a file
我试着这样:
$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]在路径中找不到文件: C:/xampp/htdocs/myshop/public/img/products/147/Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png
如果我dd($ destination_path,$ new_file_name),结果:
C:\ XAMPP \ htdocs中\ myshop \公共\ IMG \产品\ 147 \ Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png
C:\ XAMPP \ htdocs中\ myshop \公共\ IMG \产品\ 147 \ 147灾害-chelsea.png
我尝试检查文件夹147中的Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png,该文件存在
为什么会出现错误?
更新:
我找到了解决方案。我使用这样的PHP脚本:
rename($destination_path, $new_file_name);
。它的工作原理
答案 0 :(得分:1)
存储使用 C:/ xampp / htdocs / myshop / storage / app
但你的数据存储在公共路径上
您可以使用 \ 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);
}