我正在尝试将图像插入我项目中的数据库,但未按预期工作,我不确定在哪里出错。我不断从警报模板中收到此错误消息。
该图像必须是图像。图片必须是以下类型的文件:jpeg,png,jpg,gif,svg。
表示上传的图片是Jpeg格式的图片。我需要帮助
public function register(Request $request){
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$newStudent = new Student;
if($file = $request->hasFile('image')) {
$file = $request->file('image') ;
$fileName = $file->getClientOriginalName() ;
$destinationPath = public_path().'/uploads/' ;
$file->move($destinationPath,$fileName);
$newStudent->image = '/public/uploads/'.$fileName ;
}
$newStudent -> StudentID = $request -> input('StudentID');
$newStudent -> cLevel = $request -> input('cLevel');
$newStudent -> surName = $request -> input('surName');
$newStudent -> fName = $request -> input('fName');
$newStudent -> fEmail = $request -> input('fEmail');
$newStudent -> DoB = $request -> input('DoB');
$newStudent -> pAddress = $request -> input('pAddress');
$newStudent -> save();
return response()->json(['status' => 'Image Uploaded Successfully']);
}
请在<form ... enctype="multipart/form-data">
标签中添加行
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句