码迷,mamicode.com
首页 > 其他好文 > 详细

Magento 图片resize 跟upload图片(记录用)

时间:2015-10-22 12:07:03      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

1:图片resize

       $imageUrl = Mage::getBaseUrl("media").‘reviewimages/‘.$_review->getReviewimage();
               
                $imageName = $_review->getReviewimage();
                $imageResized = Mage::getBaseDir(‘media‘).DS."creviewimages".DS.$imageName;
                $dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($imageUrl,‘/media‘));
                if (!file_exists($imageResized)&&file_exists($dirImg)) :
                $imageObj = new Varien_Image($dirImg);
                $imageObj->constrainOnly(TRUE);
                $imageObj->keepAspectRatio(TRUE);
                $imageObj->keepFrame(FALSE);
                $Resolution = Mage::helper("reviewimage")->getResolution();
                $imageObj->resize($Resolution);
                $imageObj->save($imageResized);
                endif;

2.上传图片

    
          if(isset($_FILES[‘reviewimage‘][‘name‘]) && $_FILES[‘reviewimage‘][‘name‘] != ‘‘) {
                try {    
                    /* Starting upload */    
                    $uploader = new Varien_File_Uploader(‘reviewimage‘);
                    
                    // Any extention would work
                       $uploader->setAllowedExtensions(array(‘jpg‘,‘jpeg‘,‘gif‘,‘png‘));
                    $uploader->setAllowRenameFiles(false);
                    
                    // Set the file upload mode
                    // false -> get the file directly in the specified folder
                    // true -> get the file in the product like folders
                    //    (file.jpg will go in something like /media/f/i/file.jpg)
                    $uploader->setFilesDispersion(false);
                            
                    // We set media as the upload dir
                    $path = Mage::getBaseDir(‘media‘).DS.reviewimages.DS;
                    $uploader->save($path, $_FILES[‘reviewimage‘][‘name‘] );
                    
                } catch (Exception $e) {
              
                }
            
                //this way the name is saved in DB

            }

      

Magento 图片resize 跟upload图片(记录用)

标签:

原文地址:http://www.cnblogs.com/varliny/p/4900311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!