I'm tryng to upload image from a form in laravel but i get this in postman on dd($request->image)
Laravel version is 8.12
i have problem to get images on request , i've used/imported Request $request in my function and globally in my controller
Illuminate\Http\UploadedFile {#1900
-test: false
-originalName: "IMG_20211015_104550_306.jpg"
-mimeType: "image/jpeg"
-error: 0
#hashName: null
path: "C:\xampp\tmp"
filename: "php9F5A.tmp"
basename: "php9F5A.tmp"
pathname: "C:\xampp\tmp\php9F5A.tmp"
extension: "tmp"
realPath: "C:\xampp\tmp\php9F5A.tmp"
aTime: 2022-03-11 09:47:40
mTime: 2022-03-11 09:47:40
cTime: 2022-03-11 09:47:40
inode: 6192449487666182
size: 153950
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\xampp\tmp\php9F5A.tmp"
}
in my controller:
if (isset($request->immagini)) {
$realPath=[];
foreach ($request->file('immagini') as $key => $value) {
dd($value);
// $realPath = $value->store('images/mail', 'public');
$realPath =Storage::disk('public')->put('images/mail', $value);
}
}
else {
$realPath=null;
}
$data = [
$request->type,
$realPath,
$nome,
$mailMittente,
$telefono,
$anno,
$info,
$km,
$cilindrata,
$alimentazione,
$targa,
$marca,
$cognome,
$modello
];
dd($request->immagini);
i can't access to dd($value) and i get realPath=[].
CodePudding user response:
you try this way:
$file->getRealPath();
CodePudding user response:
Please try this for store file in storage
if ($request->file('immagini')) {
$realPath = Storage::disk('public')->put('images/mail',file_get_contents($request->file('immagini')));
} else {
$realPath = null
}