00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Catalog_Model_Category_Attribute_Backend_Image extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
00036 {
00037
00038
00039
00040
00041
00042
00043 public function beforeSave($object)
00044 {
00045 $value = $object->getData($this->getAttribute()->getName());
00046
00047 if (is_array($value) && !empty($value['delete'])) {
00048 $object->setData($this->getAttribute()->getName(), '');
00049 $this->getAttribute()->getEntity()
00050 ->saveAttribute($object, $this->getAttribute()->getName());
00051 return;
00052 }
00053
00054 $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
00055
00056 try {
00057 $uploader = new Varien_File_Uploader($this->getAttribute()->getName());
00058 $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
00059 $uploader->setAllowRenameFiles(true);
00060 $uploader->save($path);
00061
00062 $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName());
00063 $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
00064 } catch (Exception $e) {
00065
00066 return;
00067 }
00068
00069 }
00070
00071 }