1
votes

Am trying to insert image into a database in my project but things ain't working as expected, Am not sure as to where am getting it wrong. i keep getting this error message from my alert template.

enter image description here

The image must be an image. The image must be a file of type: jpeg,png, jpg, gif, svg.

mean while the uploaded image is an image with Jpeg format. i need help

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']);
}

1
can you please paste your html form here?Kamran

1 Answers

1
votes

Please add line in your <form ... enctype="multipart/form-data"> tag