2017-10-11 187 views
0

我从这里看到:rename a directory or a 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); 

存在着错误:

[联赛\ Flysystem \ FileNotFoundException异常]在路径未找到文件: C:/xampp/htdocs/myshop/public/img/products/147/Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

如果我的DD($ destination_path可,$ new_file_name),结果:

C:\ XAMPP \ htdocs中\ myshop \ PUBLIC \ IMG \产品\ 147 \ Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

C:\ XAMPP \ htdocs中\ myshop \ PUBLIC \ IMG \产品\ 147 \ 147-危险-chelsea.png

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

为什么存在错误?

更新

我必须找到解决办法。我使用这样的PHP脚本:

rename($destination_path, $new_file_name);。它的工作原理

+0

是否没有人帮忙? –

+0

请检查dd(\ Storage :: exists($ destination_path)); – honarkhah

+0

存储使用C:/ xampp/htdocs/myshop/storage/app – honarkhah

回答

1

存储使用C:/ XAMPP/htdocs中/ myshop /存储/应用
但你的数据存储的公共路径

上,你可以使用\存储::存在($ 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); 
} 
+0

我试过你的代码。这不是错误。但它不能重命名文件名 –

+0

我找到了解决方案。我使用这样的php脚本:'rename($ destination_path,$ new_file_name);'。它的工作原理 –

+0

存储使用C:/ xampp/htdocs/myshop/storage/app,但你的文件在公共路径 – honarkhah

相关问题