예제 #1
0
 public function uploadAction()
 {
     try {
         //Mage::log($_FILES);
         /* $mageVersion = Mage::getVersionInfo();
         			if($mageVersion<'1.5.1.0'){
         				$uploader = new Mage_Core_Model_File_Uploader('image');
         			}else{				
         				$uploader = new Varien_File_Uploader('image');
         			} */
         $uploader = new Varien_File_Uploader('image');
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($this->getBaseTmpMediaPath());
         Mage::dispatchEvent('catalog_product_gallery_upload_image_after', array('result' => $result, 'action' => $this));
         /**
          * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
          */
         $result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
         $result['path'] = str_replace(DS, "/", $result['path']);
         $tempUrl = $this->_prepareFileForUrl($result['file']);
         if (substr($tempUrl, 0, 1) == '/') {
             $tempUrl = substr($tempUrl, 1);
         }
         $result['url'] = $this->getBaseTmpMediaUrl() . '/' . $tempUrl;
         /* $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']); */
         $result['file'] = $result['file'];
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
예제 #2
0
 public function uploadAction()
 {
     $result = array();
     try {
         $uploader = new Varien_File_Uploader('image');
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save(Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath());
         $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
         $result['file'] = $result['file'] . '.tmp';
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
 public function uploadAction()
 {
     //We are unable to change Varien_File_Uploader, so in case when DB storage allowed we will do next:
     //We upload image to local Magento FS, then we check whether this file exists in DB
     //If it exists, we are getting unique name from DB, and change them on FS
     //After this we upload file to DB storage
     $result = array();
     try {
         $uploader = new Varien_File_Uploader('image');
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save(Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath());
         $result['file'] = Mage::helper('core/file_storage_database')->saveUploadedFile($result);
         $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
         $result['file'] = $result['file'] . '.tmp';
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
예제 #4
0
 /**
  * Function to upload product image
  *
  * @param int $filename            
  * @param array $filesDataArray            
  * @return string
  */
 public function uploadImage($filename, $filesDataArray)
 {
     /**
      * Create instance for uploader
      */
     $uploader = new Varien_File_Uploader($filename);
     /**
      * SEt allowed extensions
      */
     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
     $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
     $uploader->setAllowRenameFiles(true);
     $uploader->setFilesDispersion(false);
     /**
      * Initilize path
      */
     $path = Mage::getBaseDir('media') . DS . 'tmp' . DS . 'catalog' . DS . 'product' . DS;
     $uploader->save($path, $filesDataArray[$filename]['name']);
     /**
      * Return path
      */
     return $path . $uploader->getUploadedFileName();
 }
예제 #5
0
 /**
  * save logo for seller
  *
  * @param array $filesDataArray            
  * @param string $basedir            
  * @return string $imagesPathLogo
  */
 public function saveLogoForSeller($filesDataArray, $basedir, $logo)
 {
     /**
      * check store logo has not been empty
      */
     $imagesPathLogoBanner = '';
     if (isset($filesDataArray[$logo]['name']) && file_exists($filesDataArray[$logo]['tmp_name'])) {
         try {
             $uploader = new Varien_File_Uploader($filesDataArray[$logo]);
             /**
              * Define the allowed file extension of uploading file
              */
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
             $uploader->setAllowRenameFiles(true);
             $uploader->setFilesDispersion(false);
             $path = $basedir . DS . 'sellerimage';
             /**
              * upload the file to the images path
              */
             $uploader->save($path, $filesDataArray[$logo]['name']);
             $imagesPathLogoBanner = $uploader->getUploadedFileName();
         } catch (Exception $e) {
             /**
              * Display error message for images upload
              */
             Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
         }
         /**
          * check for resized directory and create new one if its not exist already
          */
         Mage::getModel('marketplace/seller')->createDirecotryForSellerProfileImage($basedir, 2);
         /**
          * Define the logo and resized logo paths
          */
         if ($logo == 'store_logo') {
             $imageUrlLogo = Mage::getBaseDir('media') . DS . 'sellerimage' . DS . $imagesPathLogoBanner;
             $imageResizedLogo = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'resized' . DS . $imagesPathLogoBanner;
         } else {
             $imageUrlLogo = Mage::getBaseDir('media') . DS . 'sellerimage' . DS . $imagesPathLogoBanner;
             $imageResizedLogo = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'resized' . DS . $imagesPathLogoBanner;
         }
         /**
          * check the file is in logo path and not in resized logo path
          */
         if (file_exists($imageUrlLogo) && !file_exists($imageResizedLogo)) {
             /**
              * Define the atributes before resize
              */
             $imageObj = new Varien_Image($imageUrlLogo);
             $imageObj->constrainOnly(TRUE);
             $imageObj->keepAspectRatio(False);
             $imageObj->keepFrame(FALSE);
             /**
              * Resize the image according to the atributes
              */
             if ($logo == 'store_logo') {
                 $imageObj->resize(150, 110);
             } else {
                 $imageObj->resize(750, 230);
             }
             /**
              * Saving the Resized image
              */
             $imageObj->save($imageResizedLogo);
         }
     }
     return $imagesPathLogoBanner;
 }