...
Code Block | ||
---|---|---|
| ||
{ // Saving only the main portion of the uploaded file's name, without the file extension. Configuration::updateValue( 'BLOCKADVERT_IMG_EXT', substr($_FILES['adv_img']['name'], strrpos($_FILES['adv_img']['name'], '.') + 1) ); // Setting the image name with a name contextual to the shop context. $this->adv_imgname = 'advertising'; // Creating two versions of the contextual name, depending on the context. if (Shop::getContext() == Shop::CONTEXT_GROUP) $this->adv_imgname = 'advertising'.'-g'.(int)$this->context->shop->getContextShopGroupID(); elseif (Shop::getContext() == Shop::CONTEXT_SHOP) $this->adv_imgname = 'advertising'.'-s'.(int)$this->context->shop->getContextShopID(); // Copying the image in the module directory with its new contextual name. if (!move_uploaded_file($_FILES['adv_img']['tmp_name'], _PS_MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT'))) $errors .= $this->l('File upload error.'); } |
Code Block | ||
---|---|---|
| ||
protected function initialize() { // Setting the main name of the image. $this->adv_imgname = 'advertising'; // Setting the contextual name of the file, depending on the context. if ((Shop::getContext() == Shop::CONTEXT_GROUP || Shop::getContext() == Shop::CONTEXT_SHOP) && file_exists(_PS_MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'-g' .$this->context->shop->getContextShopGroupID().'.'.Configuration::get('BLOCKADVERT_IMG_EXT'))) $this->adv_imgname .= '-g'.$this->context->shop->getContextShopGroupID(); if (Shop::getContext() == Shop::CONTEXT_SHOP && file_exists(_PS_MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'-s' .$this->context->shop->getContextShopID().'.'.Configuration::get('BLOCKADVERT_IMG_EXT'))) $this->adv_imgname .= '-s'.$this->context->shop->getContextShopID(); $this->adv_img = Tools::getMediaServer($this->name)._MODULE_DIR_.$this->name.'/' .$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT'); } |
...