I'm stuck in image upload in cakephp 3.8.13....is there anyone who can help!

if ($request_data[‘image_name’][‘tmp_name’]) {
$file = $request_data[‘image_name’];
$ext = substr(strtolower(strrchr($file[‘name’], ‘.’)), 1); //get the extension
$arr_ext = array(‘jpg’, ‘jpeg’, ‘png’); //set allowed extensions
$setNewFileName = time() . “_” . rand(000000, 999999);
$imageFileName = WWW_ROOT . ‘uploads/Student/student_image/’ . $setNewFileName . ‘.’ . $ext;
}

        if (in_array($ext, $arr_ext)) {
            move_uploaded_file($file['tmp_name'], WWW_ROOT . '/uploads/Student/student_image/' . $setNewFileName . '.' . $ext);
            $imageFileName = $setNewFileName . '.' . $ext;
            
        }

Actually this code is working for add function,but i need to resize images and edit the image as well…TIA

The only CakePHP specific plugin which kind of does what you want is GitHub - brandcom/cakephp-assets: Backend Asset Management for CakePHP

But it is a kind of full assett management plugin which provides helper methods to output specific widths, image types etc.

So if you want you could look at its implementation which basically uses Intervention Image | Intervention Image v2 | intervention.io to do whatever you want with images (if your PHP installation has support for whatever image manipulation you desire)

1 Like