0

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

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.php – Robert Nov 29 '17 at 15:33
  • can you post your module files content? EDIT: didnt see your link – juhanix Nov 29 '17 at 15:34
  • is done please take a look I edit my post – Robert Nov 29 '17 at 15:38
  • you have everything you need now? please let me know – Robert Nov 29 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.