laravel-8 - 如何获取图像的原始名称?
问题描述
大家好如何获取集合中图像的原始客户端名称?
我有这个新代码可以上传三个以上的图像
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
我想要的是保存图像的原始名称。
解决方案
我通常做的是将文件名设置为 uuid 以存储在系统中,但将原始文件名保留在数据库中,以便您可以根据需要重命名以进行下载。要获取原始文件名,您需要查看帖子数据。
像这样:
$this->active_document->original_filename = $this->uploaded_file->getClientOriginalName();
文档中的更多信息:https ://laravel.com/docs/8.x/filesystem#file-uploads
推荐阅读
- ios - 取消选择时如何停止 UITableViewCell 闪烁为白色?
- python - 关于 CMD Manifest.json 和 python 文件
- angular - Ngrx 商店组织
- html - 纯CSS中的可折叠文本高度
- html - 电子邮件中的表头在 iOS 中的画外音(ADA)中宣布两次(仅第一列宣布两次)
- django - 如何在Django内部重定向html页面?
- javascript - 如何将值(项目)从一个 Netsuit 业务系统表单自动传输到另一个 Netsuit 表单?
- php - 如何在 Symfony Forms 中使用约束来制作必填字段?
- python - Django 模型对象的布尔值未呈现
- r - 是否有基于唯一日期和时间戳提取图像的 R 函数?