File upload and validation in codeIgniter 4

Get file

$image= $this->request->getFile("image");
 

Create new random name

$new_name=$image->getRandomName();
 

Upload new image to the specified folder

$image->move("./public/blog_uploads", $new_name);
 

File validation

'image'=>'uploaded[image]|max_size[image,1024]|ext_in[image,png,jpg,gif,html]'
© 2016 - 2022, All Rights are Reserved.