【问题标题】:How to rename a image on server location using laravel如何使用 laravel 重命名服务器位置上的图像
【发布时间】:2019-08-27 10:53:09
【问题描述】:

我想重命名一个文件名,我想更改旧名称。

    I have tried Storage::move('old_image path','new image path');

    $file=ClientDocument::where('id',$request->id)->first();

    Storage::move(url('/').'/file/'.$file->file,url('/').'/file/'. $request->file);

当我使用这个 Storage::move(url('/').'/file/'.$file->file,url('/').'/file/'.$request->file );

它显示一个错误

在路径中找不到文件:https://test.heartlandpar.com/public/file/99d0e66a-68e2-482c-8723-1bba1d35b871_rw_1920.jpg

但是当我在浏览器中点击这个网址时,图像在浏览器中打开。

【问题讨论】:

  • 能否请您发布错误

标签: laravel


【解决方案1】:

您可以使用条件来检查文件是否存在于该位置。 如果文件存在,则显示错误。或存储文件。

$exists = Storage::disk('spaces')->exists('FMSuploads/VehicleDoc/'.$file->getClientOriginalName());
                        if($exists){
                            \Session::flash('error', 'File name already exist');
                            return redirect()->back()->withInput();
                        }
                       else{
                        Storage::disk('spaces')->putFileAs('FMSuploads/VehicleDoc', $file, $file->getClientOriginalName(), 'public');
                         log::info('document uploaded successfullly');
                       }

或查看此帖子File rename in laravel

【讨论】:

  • 但是我想重命名一个已经在我的公共路径文件夹中的文件。
  • @JogenderDelaine 我已经修改了我的问题。请检查一下
  • 你能解释一下 disk('spaces') 吗?我是第一次使用。
  • @JogenderDelaine 用于指定您在文件系统中使用的磁盘。检查 /config/filesystems.php 中的文件。它具有文件系统配置。例如,如果您在 aws 中有存储空间,它将有 s3 ,。如果文件在 local ,则在 'local' 或 public 中配置。
  • 我检查了我的文件,在文件中有本地的。所以现在我需要在 s3 的地方使用本地。
猜你喜欢
  • 2010-12-08
  • 2019-03-04
  • 1970-01-01
  • 2022-07-25
  • 1970-01-01
  • 2014-04-02
  • 2017-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多