如何获取存储在存储中的图像的路径或名称?

时间:2018-02-07 08:14:41

标签: laravel laravel-5

我试图将图像存储在数据库中的图像名称存储中。

$file = $request->file('attachments');
Storage::disk('public')->put('images',$file);

$attachments = new Attachment();
$attachments->title = $title;
$attachments->path = "NAME OF IMAGE THAT ALREADY STORED ($FILE)";

$inbox_attachments->save();

图片名称示例为

  

5MgomzwHmMxUhKqRu7T4SMhjvfrWtdKLArBSc3bI.jpg

1 个答案:

答案 0 :(得分:2)

使用basename

  

basename - 返回路径的尾随名称组件

试试这个:

$storagePath = Storage::disk('public')->put('images',$file);

$attachments->path = basename($storagePath);