How do I capture originalName in laravel 7 using NowUI dashboard?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-08 10:40:31

问题


I am trying to upload an image using Laravel 7. I have displayed the form input using dd() and am getting the bellow output for profile image. How doi I capture the originalName and save to the database?

"profile_image" => Illuminate\Http\UploadedFile {#1251 ▼
-test: false
-originalName: "dvdvdvd.png"
-mimeType: "image/png"
-error: 0
#hashName: null
path: "/tmp"
filename: "phpMTKWo0"
basename: "phpMTKWo0"
pathname: "/tmp/phpMTKWo0"
extension: ""
realPath: "/tmp/phpMTKWo0"
aTime: 2020-09-28 09:58:13
mTime: 2020-09-28 09:58:13
cTime: 2020-09-28 09:58:13
inode: 63413
size: 29795
perms: 0100600
owner: 33
group: 33
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false

}


回答1:


use getClientOriginalName() ref link https://laravel.com/docs/8.x/filesystem#file-uploads

$image = $request->file('profile_image');
$filename = $image->getClientOriginalName();

// store the file
$imagePath = $image->storeAs("/path/", $filename);





回答2:


You can use getClientOriginalName method on UploadedFile object:

$name = $request->profile_image->getClientOriginalName();

See more here: https://laravel.com/docs/7.x/filesystem#file-uploads



来源:https://stackoverflow.com/questions/64100119/how-do-i-capture-originalname-in-laravel-7-using-nowui-dashboard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!