我从这里看到: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] 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\products\147\Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png
C:\xampp\htdocs\myshop\public\img\products\147\147-hazard-chelsea.png
我尝试检查文件夹147中的Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png,该文件存在
为什么会出现错误?
更新:
我已经找到解决方案了。我使用这样的 php 脚本:
重命名($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);
}
关于image - 重命名文件时如何解决在路径 :. .. 处找不到文件? (拉拉维尔),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46679815/