SaveToFile() function with Multiple upload

I made a script to crop my image files on upload, when insert or update and it’s work, I use a code like this:Here a snipt of my code to better unsertanding:

CustomResize($this->img, rv_ClearString($rsnew['img']), 1000, 300, "./images/tb/");

function CustomResize($cp_origFile, $new_files, $final_width_file, $final_height_file, $file_tbFolder)
{
    $images = explode(",", $new_files);
       
    //Define a pasta onde será gravada o Thumbnail
    $thumbPath = $cp_origFile->UploadPath . $file_tbFolder;
   
    //move_uploaded_file($cp_origFile->Upload->FileName, $thumbPath);
    foreach($images as $new_file)
    {
                //Try to send to server, 
		$cp_origFile->Upload->SaveToFile($thumbPath, $new_file, TRUE); ------->That is here that not working
                ...
                <RESIZE AND CROP THIS IMG >
                but this image filename doesn't exist in server, and create a blank croped image
        ...
    }
}

I made some tests and SaveToFile function doesn’t work, because the $this->Value in cUpload class is empty, when it should have the image to upload. Next goes some prints of variable when try to upload multiple images:
row_updt: test1.jpg,test2.jpg,test3.jpg,test4.jpg → in row_updating(), the $rsnew[‘img’] variablecustomResize() - new_file: test1.jpg → value sent after made the explode (sent to save each image)
$this->Value: null
path: C:\Program Files\EasyPHP\data\localweb\quintadalixa.pt\assets\images\conteudos
NewFileName: test1.jpg
this->FileName: test1.jpg,test2.jpg,test3.jpg,test4.jpgcustomResize - new_file: test2.jpg
$this->Value: null
path: C:\Program Files\EasyPHP\data\localweb\quintadalixa.pt\assets\images\conteudos
NewFileName: test2.jpg
this->FileName: test1.jpgcustomResize - new_file: test3.jpg
$this->Value: null
path: C:\Program Files\EasyPHP\data\localweb\quintadalixa.pt\assets\images\conteudos
NewFileName: test3.jpg
this->FileName: test2.jpgMy qestion is how to pre-upload files to server with SaveToFile() function or other, for crop image after.

The Upload object is a property of a field object, if you use multiple upload for the field, the Upload->Value property does NOT contain binary data of multiple files. You need to split the Upload->FileName (which is comma separated file names), loop through them and copy and crop each file, which can be accessed by, e.g. (Add/Edit page, v11 only)ew_UploadTempPath($this->YourField->FldVar) . EW_PATH_DELIMITER . $file

(where $file is the individual file name in the loop)

It works, thank you so much.

I upgraded to PHPMaker 2021 version, and this code doesn’t work, because there are many other functions e variables.There is some native functionality on version 2021 that crop image and copy to specified folder?Thanks in advance.

You need to update the code, read Migrating to v2019.

OK, I will chek it out.By the away, how to activate thumbnail image.
When we select the image to upload, PHPMaker create a thumbnail in temp folder, but when I click in save button, only original image is uploaded.There is some configuration to copy the thumbnail to specified folder?PS: I already config thumbnails width and height, on “Advanced Settings”.

Thumbnails are created dynamical when users view the record, just enable “Resize image” in View Tag panel.If you need to create a thumbnail for your own use, there is another method resizeAndSaveToFile(). From the source:

    /**
     * Resize and save uploaded data to file
     *
     * @param int $width Target width of image
     * @param int $height Target height of image
     * @param int $quality Deprecated, kept for backward compatibility only.
     * @param string $newFileName New file name
     * @param bool $overWrite Overwrite existing file or not
     * @param int $idx optional Index of the file
     * @return HttpUpload
     */
    public function resizeAndSaveToFile($width, $height, $quality, $newFileName, $overWrite, $idx = -1)