Jump to content

New Block - Picture Block


getstock
 Share

Recommended Posts

Hi all, I am trying to create a block that will simply display a .jpg image, which you should be able to load from the options on the module tab. I have borrowed code from all over the place and suprise suprise it does not work.

I have some experience with PHP, but none with smarty so not really sure what I am doing!

Basically this is what I have so far, It comes up with an installation error:

<?php


class blockpicture1 extends Module
{    
   function __construct()
   {
        $this->name = 'blockpicture1';
        $this->tab = 'Tools';
        $this->version = '1.0';
       $this->displayName = $this->l('Picture Block 1');

        parent::__construct();


       $this->description = $this->l('Add a picture');
       $this->confirmUninstall = $this->l('Remove Image?');
   }

   function install()
   {
       if (!parent::install())
           return false;
       if (!$this->registerHook('left'))
           return false;
       return true;
   }

   function uninstall()
   {
       if (!Configuration::deleteByName('blockpicture1') OR !parent::uninstall())
           return false;
       return true;
   }
   function getContent()

           {
   /* upload the image */
               if (isset($_FILES['block_picture_1']) AND isset($_FILES['block_picture_1']['tmp_name']) AND !empty($_FILES['block_picture_1']['tmp_name']))
                   {
               Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);
               if ($error = checkImage($_FILES['block_picture_1'], $this->maxImageSize))
                   $errors .= $error;
               elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['block_picture_1']['tmp_name'], $tmpName))
                   return false;
               elseif (!imageResize($tmpName, dirname(__FILE__).'/block_picture_1.jpg'))
                   $errors .= $this->displayError($this->l('An error occurred during the image upload.'));
               unlink($tmpName);
                   }
           }

   function hookLeft($params)
   {


   }

}

?>



Am I even close on getting this somewhere close to working? Or am I so far off that I haven't got a hope in hell! Could somene be kind enough to give me some pointers.

Many thanks

Dave

Share this post


Link to post
Share on other sites

I suggest that you download Prestashop v1.3 alpha 1 and copy modules/blockadvertising into your Prestashop. It should work in Prestashop v1.2.5 too, I think. This module lets you choose a JPEG image from the configuration page.

Share this post


Link to post
Share on other sites

  • 3 weeks later...
<? 


           if (isset($_FILES['imagename']) AND isset($_FILES['imagename']['tmp_name']) AND !empty($_FILES['imagename']['tmp_name']))
           {
               $idcat = $_REQUEST['idcat'];
$lang =$_REQUEST['lang'];
               Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);
               if ($error = checkImage($_FILES['imagename'], $this->maxImageSize))
                   $errors .= $error;
               elseif (!$tmpName = "images/" /*tempnam(_PS_TMP_IMG_DIR_, 'PS')*/ OR !move_uploaded_file($_FILES['imagename']['tmp_name'], $tmpName))
                   return false;
               elseif (!imageResize($tmpName, dirname(__FILE__).'/ClassicDesignShop_'. $idcat . "_" . $lang . '.jpg'))
                   $errors .= $this->displayError($this->l('An error occurred during the image upload of box 3 ita.'));
               unlink($tmpName);
           }
?>



This upload to the file where i have the class file in the admin tabs. Can some one edit so that I can upload to the root/images/category please instead of the temporary file as i am changing the tempname and it does not work. Please Help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More