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
}