【问题标题】:How to get original name of the image?如何获取图像的原始名称?
【发布时间】:2021-08-16 08:03:27
【问题描述】:

大家好,如何获取集合中图片的原始客户端名称?

我有这个新代码可以上传三张以上的图片

public function store(){

        $action = '';

        $data =  $this->validate([
            'album_title' => 'required',
            'photos.*' => 'image|max:2000', // 2MB Max
        ]);

        //New Code with collections
        $filenames = collect($this->photos)->map->store('photos');

        if($this->galleryId){
            Gallery::find($this->galleryId)->update($data);
            $action = 'edit';
        }else{
            // Gallery::create($data);
            Gallery::create([
                'album_title' => $this->album_title,
                'photos' => $filenames->implode(','),
              ]);
            $action = 'store';
        }
        $this->emit('showEmitedFlashMessage', $action);
        $this->resetInputFields();
        $this->emit('refreshParent');
        $this->emit('closeGalleryModal');

    }

但它保存了这样的东西

photos/xTNV0cQ7YzpyUsJ6OdrpQirwfCPdzDtKJAKoWUFm.jpg,photos/32PkRR9bFhM7BqAy9OWG05m5fe53PUXtidEMhlnn.jpg,photos/Dyps8wCsga0zdALGsKEOS9jcYSNshnixw4UWzhEL.jpg

我想要的是保存图像的原始名称。

【问题讨论】:

    标签: laravel-8 laravel-livewire


    【解决方案1】:

    我通常所做的是将文件名设置为 uuid 以存储在系统中,但将原始文件名保留在数据库中,以便您可以根据需要重命名以进行下载。要获取原始文件名,您需要查看帖子数据。

    像这样:

    $this->active_document->original_filename = $this->uploaded_file->getClientOriginalName();
    

    文档中的更多信息:https://laravel.com/docs/8.x/filesystem#file-uploads

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      相关资源
      最近更新 更多