【问题标题】:How can I solve File not found at path:... when rename file? (laravel)如何解决 File not found at path:... 重命名文件时? (拉拉维尔)
【发布时间】:2018-03-22 15:11:04
【问题描述】:

我从这里看到: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\public\img\products\147\Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

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

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

为什么会出现错误?

更新

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

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

【问题讨论】:

  • 有没有人帮忙?
  • 请检查 dd(\Storage::exists($destination_path));
  • 存储使用C:/xampp/htdocs/myshop/storage/app
  • @honarkhah,如果我这样做dd(\Storage::exists($destination_path));,结果:false

标签: image laravel laravel-5.3 filenames file-rename


【解决方案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);
}

【讨论】:

  • 我试过你的代码。这没有错误。但是重命名文件名不起作用
  • 我找到了解决方案。我使用这样的 php 脚本:rename($destination_path , $new_file_name );。它有效
  • 存储使用 C:/xampp/htdocs/myshop/storage/app 但您的文件在公共路径上
  • 如果要使用存储,首先必须将文件保存到存储路径,然后才能使用存储,但是当您将文件保存到公共路径时,必须使用纯php函数
猜你喜欢
  • 2022-10-17
  • 2021-07-31
  • 2018-10-19
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多