1

I am Working on custom Module In Magento 2 I m trying to upload image to database using fileUploaderFactory.

try {
        $uploader = $this->_fileUploaderFactory->create(['fileId' => 'image']);
        $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
        $uploader->setFilesDispersion(false);
        $uploader->setAllowRenameFiles(true);
        $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('backgroundimage/');
        $filename=$data['title'].$data['date_from'];
        $filename = str_replace(' ', '_', $filename);
        $uploader->save($path,$filename);

    } catch (Exception $e) {
        $this->messageManager->addError(__($e->getMessage()));
    }

File is Upload in database but i m not getting File extension that is why file is not showing in my GRID list

Anyone please Guide

  • $uploader = $this->_fileUploaderFactory->create(['fileId' => 'Your_Column_Name']) check it – Rk Rathod Mar 18 at 6:26
  • I wanna Check whether it is jpg/Png/jpeg – Waqar Ali Mar 18 at 9:05
  • try to comment this line $filename = str_replace(' ', '_', $filename); and check – fmsthird Mar 26 at 11:40
  • $ext=pathinfo($filename,PATHINFO_EXTENSION); – Purnendar Gattu Mar 26 at 13:14

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.