0

i have done this: but it is not showing banner image: step1.

/app/code/local/Company/ModName/Block/Adminhtml/ModName/Edit/Tab/Form.php

$fieldset->addField('banner_image', 'file', array(
          'label'     => Mage::helper('pictos')->__('Banner Image'),
          'required'  => false,
          'name'      => 'banner_image',
)); 

step2.

if(isset($_FILES['banner_image']['name']) and (file_exists($_FILES['banner_image']['tmp_name']))) {
  try {
    $uploader = new Varien_File_Uploader('banner_image');
    $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); 
    $uploader->setAllowRenameFiles(false);

    // setAllowRenameFiles(true) -> move your file in a folder the magento way
    // setAllowRenameFiles(true) -> move your file directly in the $path folder
    $uploader->setFilesDispersion(false);

    $path = Mage::getBaseDir('media') . DS .blog. DS ;

    $uploader->save($path, $_FILES['banner_image']['name']);

    $data['banner_image'] = $_FILES['banner_image']['name'];
  }catch(Exception $e) {

  }
} 
else {      

    if(isset($data['banner_image']['delete']) && $data['banner_image']['delete'] == 1)
        $data['image_main'] = '';
    else
        unset($data['banner_image']);
}

step three:

$installer->startSetup();
$installer->getConnection()->addColumn(
    $installer->getTable('blog/post'),
    'banner_image',
    'VARCHAR(255) NULL'
);
$installer->endSetup();

in frontend i call banner image like this:

if($this->getpost()->getBannerImage()){?>
        <div class="banner_area">
<?php $imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'/blog/'.$this->getpost()->getBannerImage();?>
            <img src="<?php echo $imageUrl;?>" alt="<?php echo $this->getpost()->getBannerImage();?>">
        </div> 

but no result

1 Answer 1

1

I can see one thing straight off you have your path set wrong in your controller.

 $path = Mage::getBaseDir('media') . DS .blog. DS ;

should be

$path = Mage::getBaseDir('media') . DS .'blog'. DS ;
2
  • Hi, eirik sorry .. $path = Mage::getBaseDir('media') . DS .'blog'. DS ; i have done this too ... but there is no result ... is there any issue with file permission with magento skin folder i don't see any folder with name blog in my skin images directory... but in media folder there is a folder for blog with but there is no image which i save from admin of my module .... May 19, 2017 at 5:57
  • Inside the database table for the blog post. What is it saving the image name as? Also ensure the images don't have spaces/special characters in their names.
    – Eirik
    May 19, 2017 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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