Cakephp 3 upload images into folder with original, small and large image resized

Hello World,

these few months, i’m more on Ionic/Typescript/Angular as a result, i forgot how to write Cakephp…

few months ago, i manage to upload image and categories via folder.

my task is to upload of an image, system will create 3 images

inside webroot

file/image/products/$id
file/image/products/large/$id
file/image/products/small/$id

i found did a code, but its for User Profile Image

  	if ($this->request->is(['patch', 'post', 'put'])) {

        if (!empty($this->request->data['profile_img']['name'])) {
            $fileName = $this->request->data['profile_img']['name']; 

            $profile_img = $fileName;

            $extm = substr(strtolower(strrchr($fileName, '.')), 1); //get the extension
            $arr_extm = array('jpg', 'jpeg', 'gif', 'png'); //set allowed extensions
            if (in_array($extm, $arr_extm)) {
				
				$uploadPath =  'images' . DS . 'profile' . DS . 'media'. DS;
               
                $uploadFile = $uploadPath . $fileName;
                if(!is_dir($uploadPath)) {
                mkdir($uploadPath);
                }

                $auto = $this->generateRandomString(6);
                //$files_image='product_'.$auto.'_'.$image_id.'_'.$images['name'];
                $files_image = 'profile_' . $auto . '_' . $id . '_' . $fileName;


                $test = $uploadPath. $files_image;

               
                move_uploaded_file($this->request->data['profile_img']['tmp_name'], $test );
                $this->request->data['profile_img'] = $test;

                $source_image =  $test;
                $destination_thumb_path = WWW_ROOT. $uploadPath. DS . 'small' . DS . $files_image;
                $destination_thumb_path1 = WWW_ROOT. $uploadPath . DS . 'large' . DS . $files_image;
                // $directory = new Folder();
                $this->imageresize2($source_image, $destination_thumb_path, 270, 320, 1);
                $this->imageresize2($source_image, $destination_thumb_path1, 500, 500, 1);
            }
        }

how can i modify the above code to become the following?

file/image/products/$id
file/image/products/large/$id
file/image/products/small/$id

this task initially they use a upload component to upload image, but there’s no documents on how to insert large and small folder, i’m thinking of making it simplier.

best regards and have a nice day.

Looks like you just need to change the definition of $uploadPath and maybe the field name profile_img?

ya, thank you very much, long time no text with Zuluru already.

its done, managed to upload original file, resized into large and small folders.

:bowing_man: :bowing_man: :bowing_man: