$pic = $this->request->getFile('image'); if ($pic->isValid()) { //let set the rules $profile_pic = [ 'photo' => [ 'label' => 'Image', 'rules' => 'uploaded[image]|max_size[image,2048]|is_image[image]', 'errors' => [ 'max_size' => 'The uploaded image not accepted', 'is_image' => 'Image format not accepted' ] ] ]; //now let validate the picture if (!$this->validate($profile_pic)) { //let store the error here $errors = array( 'error' => $validation->listErrors('error_msg') ); //show the error session()->setFlashdata($errors); return redirect()->back()->withInput(); } else { //this is to get random $name = $pic->getRandomName(); $pic->move('./assets/images/blog/', $name); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter