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
1 Answer 1
if you are uploading to the media folder then following could should just do fine:
<?php echo $block->getMediaUrl($config->getImageUpload());?>
-
thank you but it doesn't return anything, is blank, if you take a look in that module they have something a function called protected function _getUploadDir() in the Image.phpRobert– Robert2017年11月29日 15:33:09 +00:00Commented Nov 29, 2017 at 15:33
-
can you post your module files content? EDIT: didnt see your linkjuhanix– juhanix2017年11月29日 15:34:17 +00:00Commented Nov 29, 2017 at 15:34
-
is done please take a look I edit my postRobert– Robert2017年11月29日 15:38:30 +00:00Commented Nov 29, 2017 at 15:38
-
you have everything you need now? please let me knowRobert– Robert2017年11月29日 16:10:47 +00:00Commented Nov 29, 2017 at 16:10
Explore related questions
See similar questions with these tags.