/** * Export attribute value to entity model * * @param Mage_Core_Model_Abstract $entity * @param array|string $value * @return Mage_Customer_Model_Attribute_Data_File */ public function compactValue($value) { if ($this->getIsAjaxRequest()) { return $this; } $attribute = $this->getAttribute(); $original = $this->getEntity()->getData($attribute->getAttributeCode()); $toDelete = false; if ($original) { if (!$attribute->getIsRequired() && !empty($value['delete'])) { $toDelete = true; } if (!empty($value['tmp_name'])) { $toDelete = true; } } $ioFile = new Varien_Io_File(); $path = Mage::getBaseDir('media') . DS . 'customer'; $ioFile->open(array('path' => $path)); // unlink entity file if ($toDelete) { $this->getEntity()->setData($attribute->getAttributeCode(), ''); $file = $path . $original; if ($ioFile->fileExists($file)) { $ioFile->rm($file); } } if (!empty($value['tmp_name'])) { try { $uploader = new Mage_Core_Model_File_Uploader($value); $uploader->setFilesDispersion(true); $uploader->setFilenamesCaseSensitivity(false); $uploader->setAllowRenameFiles(true); $uploader->save($path, $value['name']); $fileName = $uploader->getUploadedFileName(); $this->getEntity()->setData($attribute->getAttributeCode(), $fileName); } catch (Exception $e) { Mage::logException($e); } } return $this; }