0

I have created UI-component form.In that, I have more than 1 image fields while uploading an image where I need to check whether the image is saved in a temporary directory or not? Noe the image is saved in temporary directory as well as pub/media folder. Now I need to create new folder to save my small, large, medium,extra large in seperate folders inside my module folder. Please provide me a solution

upload.php(upload controller)

public function execute()
    {
        try {
            //Saves the image in temporary directory
            // $result = $this->imageUploader->saveFileToTmpDir('general[image]');

            if (isset($_FILES['upload']['tmp_name']['small_image'])) {
                //$this->checkImage('upload', $this->helperData->getSmallImageProperties(), 'small_image');
                $result = $this->imageUploader->saveFileToTmpDir('upload[small_image]');
            } 
            else if (isset($_FILES['upload']['tmp_name']['medium_image'])) {
               // $mediumImage = $this->checkImage('upload', $this->helperData->getMediumImageProperties(), 'medium_image');
                $result = $this->imageUploader->saveFileToTmpDir('upload[medium_image]');
            } 

            elseif (isset($_FILES['upload']['tmp_name']['large_image'])) {
               // $this->checkImage('upload', $this->helperData->getLargeImageProperties(), 'large_image');
                $result = $this->imageUploader->saveFileToTmpDir('upload[large_image]');
            }
            elseif (isset($_FILES['upload']['tmp_name']['extra_large_image'])) {
                //$this->checkImage('upload', $this->helperData->getExtraLargeImageProperties(), 'extra_large_image');
                $result = $this->imageUploader->saveFileToTmpDir('upload[extra_large_image]');
            }

}
12
  • It will be in present in Pub/media/your_folder
    – aravind
    Jan 31 '18 at 7:19
  • Now My images are saved in Pub/ media folder. But I need to save my images in specific folder(myfolder) inside pub/media.
    – Jaisa
    Jan 31 '18 at 7:28
  • You need to Specify the path for image after being saved in your code..
    – aravind
    Jan 31 '18 at 8:32
  • Refer this site webkul.com/blog/how-to-upload-image-in-magento2
    – aravind
    Jan 31 '18 at 8:33
  • I need to save in pub/media. But I need to save pub/media/Newfolder. So Where I need to created NewFolder via programatically.
    – Jaisa
    Jan 31 '18 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.