1

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

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Nov 29, 2017 at 15:24

1 Answer 1

-1

if you are uploading to the media folder then following could should just do fine:

<?php echo $block->getMediaUrl($config->getImageUpload());?>
answered Nov 29, 2017 at 15:30
4
  • 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 Commented Nov 29, 2017 at 15:33
  • can you post your module files content? EDIT: didnt see your link Commented Nov 29, 2017 at 15:34
  • is done please take a look I edit my post Commented Nov 29, 2017 at 15:38
  • you have everything you need now? please let me know Commented Nov 29, 2017 at 16:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.