问题
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