I use this module and I create a image upload field in my custom module. Everything is okay but I want to get the full url of image in the frontend. How I can do this?
if I use this in the Data.php
public function getImageUpload() {
return $this->scopeConfig->getValue('module/general/image_upload', ScopeInterface::SCOPE_STORE);
}
and this in phtml:
<?php echo $config->getImageUpload(); ?>
is return only default/image.png in frontend and I need to ger the full path (include store url and media folder). And I don't add that acl.xml in my module because I don't understand very well what is mean. Can be this the problem?
Thank you UPDATE: Image.php file
namespace MageVision\Blog4\Model\Config\Backend;
class Image extends \Magento\Config\Model\Config\Backend\Image
{
/**
* The tail part of directory path for uploading
*/
const UPLOAD_DIR = 'blog/post4';
/**
* Upload max file size in kilobytes
*
* @var int
*/
protected $_maxFileSize = 2048;
/**
* Return path to directory for upload file
*
* @return string
* @throw \Magento\Framework\Exception\LocalizedException
*/
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();
}
the module url: https://github.com/magevision/blog/tree/master/ImageUploadConfigurationField