I am new in MAgento2, and I installed custom module of Magento 2.3 to add image file upload configuration in system.xml.
But i encountred this isuue when i try to save the config :
system.xml
< ?xml version="1.0"?>
separator-top
mageplaza
Mageplaza_HelloWorld::helloworld_config
MagentoConfigModelConfigBackendImage
don/post
< ![CDATA[Allowed file types: jpg, jpeg, gif, png, svg]]>
my backend_model Image.php :
< ?php
namespace MageplazaHelloWorldModelConfigBackend;
class Image extends MagentoConfigModelConfigBackendImage
{
/**
* The tail part of directory path for uploading
*/
const UPLOAD_DIR = 'don/post';
/**
* Upload max file size in kilobytes
*
* @var int
*/
protected $_maxFileSize = 2048;
/**
* Return path to directory for upload file
*
* @return string
* @throw MagentoFrameworkExceptionLocalizedException
*/
protected function _getUploadDir()
{
return $this->_mediaDirectory->getAbsolutePath($this->_appendScopeInfo(self::UPLOAD_DIR));
}
/**
* Makes a decision about whether to add info about the scope.
*
* @return boolean
*/
protected function _addWhetherScopeInfo()
{
return true;
}
/**
* Getter for allowed extensions of uploaded files.
*
* @return string[]
*/
protected function _getAllowedExtensions()
{
return ['jpg', 'jpeg', 'gif', 'png', 'svg'];
}
/**
* @return string|null
*/
protected function getTmpFileName()
{
$tmpName = null;
if (isset($_FILES['groups'])) {
$tmpName = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
} else {
$tmpName = is_array($this->getValue()) ? $this->getValue()['tmp_name'] : null;
}
return $tmpName;
}
/**
* Save uploaded file before saving config value
*
* Save changes and delete file if "delete" option passed
*
* @return $this
*/
public function beforeSave()
{
$value = $this->getValue();
$deleteFlag = is_array($value) && !empty($value['delete']);
$fileTmpName = $this->getTmpFileName();
if ($this->getOldValue() && ($fileTmpName || $deleteFlag)) {
$this->_mediaDirectory->delete(self::UPLOAD_DIR . '/' . $this->getOldValue());
}
return parent::beforeSave();
}
}
I created also the folder pub/media/don/post/default
i did not succeed in finding a solution of this issue
Thanks in advance