我试图从laravel中的表单上传图像,但我在dd($request->image(上的poster中收到了这个
Laravel版本是8.12
我在请求时获取图像有问题,我在我的功能中使用/导入了request$request,并在我的控制器中全局使用
IlluminateHttpUploadedFile {#1900
-test: false
-originalName: "IMG_20211015_104550_306.jpg"
-mimeType: "image/jpeg"
-error: 0
#hashName: null
path: "C:xampptmp"
filename: "php9F5A.tmp"
basename: "php9F5A.tmp"
pathname: "C:xampptmpphp9F5A.tmp"
extension: "tmp"
realPath: "C:xampptmpphp9F5A.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:xampptmpphp9F5A.tmp"
}
在我的控制器中:
elseif ($request->type == 'Permuta') {
$nome = $request->nome;
$cognome = $request->cognome;
$mailMittente = $request->email;
$info= $request->info;
$telefono = $request->telefono;
$anno = $request->data;
$info = $request->info;
$km = $request->km;
$cilindrata = $request->cilindrata;
$alimentazione = $request->alimentazione;
$targa = $request->targa;
$marca= $request->marca;
$modello= $request->modello;
if (isset($request->immagini)) {
$realPath=[];
foreach ($request->immagini as $key => $value) {
$realPath[] =$value->store('images/mail', 'public');
}
}
else {
$realPath=null;
}
$data = [
$request->type,
$realPath,
$nome,
$mailMittente,
$telefono,
$anno,
$info,
$km,
$cilindrata,
$alimentazione,
$targa,
$marca,
$cognome,
$modello
];
dd($request->immagini);
}
我无法访问dd($value(,并且我得到了realPath=[]。
您可以尝试以下方式:
$file->getRealPath();
请为存储中的存储文件尝试此操作
if ($request->file('immagini')) {
$filename = '/images/mail/' .time() . '.' . $request->file('immagini')->getClientOriginalExtension();
Storage::disk('public')->put($filename, file_get_contents($request->file('immagini')));
$realPath = Storage::url($filename);
} else {
$realPath = null;
}