![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/app/code/Webkul/PrivateShop/Model/Config/Backend/ |
<?php /** * Webkul Software * * @category Webkul * @package Webkul_PrivateShop * @author Webkul Software Private Limited * @copyright Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ namespace Webkul\PrivateShop\Model\Config\Backend; use Magento\Framework\Exception\LocalizedException; /** * System config image field backend model */ class Image extends \Magento\Config\Model\Config\Backend\File { /** * Save uploaded file before saving config value * * @return $this * @throws LocalizedException */ public function beforeSave() { $maxSize = 2000000; $fileData = $this->getFileData(); $value = $this->getValue(); if (!empty($fileData)) { $uploadDir = $this->_getUploadDir(); if ($value['size'] >= $maxSize) { throw new LocalizedException( __('The file you\'re uploading exceeds the server size limit.') ); } try { /** @var Uploader $uploader */ $uploader = $this->_uploaderFactory->create(['fileId' => $fileData]); $uploader->setAllowedExtensions($this->_getAllowedExtensions()); $uploader->setAllowRenameFiles(true); $uploader->addValidateCallback('size', $this, 'validateMaxSize'); $result = $uploader->save($uploadDir); } catch (Exception $e) { throw new LocalizedException(__('%1', $e->getMessage())); } if ($result !== false) { $filename = $result['file']; if ($this->_addWhetherScopeInfo()) { $filename = $this->_prependScopeInfo($filename); } $this->setValue($filename); } } else { if (isset($value['error'])) { if ($value['error'] == 1) { throw new LocalizedException( __('The file you\'re uploading exceeds the server size limit.') ); } } if (is_array($value) && !empty($value['delete'])) { $this->setValue(''); } elseif (is_array($value) && !empty($value['value'])) { $this->setValue($value['value']); } else { $this->unsValue(); } } return $this; } /** * Getter for allowed extensions of uploaded files * * @return string[] */ protected function _getAllowedExtensions() { return ['jpg', 'jpeg', 'gif', 'png']; } }