public function getRealPath() { $options = $this->getBootstrapOptions(); $levels = $options['image']['folderlevels']; $divisionByLevel = explode(',', $options['image']['folderdivisions']); $path = APPLICATION_DATA_PATH; $path = Agana_Util_FileHandle::fixPathSeparator($path) . $options['image']['subfolder']; $path = Agana_Util_FileHandle::fixPathSeparator($path) . Agana_Util_FileHandle::genFolderNameStructure($this->_image->getFile(), $levels, $divisionByLevel); return Agana_Util_FileHandle::fixPathSeparator($path); }
private function _updateImage() { $this->_helper->viewRenderer->setNoRender(true); $layout = Zend_Layout::getMvcInstance(); $layout->disableLayout(); $return = array('msg' => '', 'file' => array('name' => '', 'size' => '', 'url' => '')); if ($this->getRequest()->isPost()) { $allowedExtensions = null; $maxSize = 999999; $path = ''; $options = $this->_getBootstrapOptions(); // UPLOAD of image $domainImage = new Media_Domain_Image(); $title = 'person_' . $this->_getParam('id'); $file = $domainImage->handleUpload(APPLICATION_DATA_PATH, array('AllowedExtensions' => $options['allowedExtensions'], 'SizeLimit' => $options['maxSize'], 'Dimensions' => $options['dimensions'])); if (isset($file['error'])) { $return['error'] = $file['error']; } else { // MEDIA MODEL $image = new Media_Model_Image(); $image->setFile($file['name']); $image->setFilesize($file['size']); $image->setMimetype($file['type']); $image->setTitle($title); // RECOVER Media from Person $domainPerson = new Persons_Domain_Person(); $person = $domainPerson->getById($this->_getParam('id')); $mp = $person->getMedia(); $createPersonMedia = !isset($mp) || $mp->getId() == null; if (!$createPersonMedia) { $image->setId($mp->getId()); } $domainImage->setImage($image); // DELETE previous image file from disk, only if they are not the same if (!$createPersonMedia) { if ($mp->getFile() != $image->getFile()) { $domainImage->setImage($mp); $domainImage->deleteFile(); $domainImage->setImage($image); } } try { // persisting media $imgId = $domainImage->save(); // persisting person media $image->setId($imgId); $person->setMedia($image); $domainPerson->setPerson($person); if ($createPersonMedia) { $domainPerson->createImageRelation(); } $return['msg'] = $this->_translate->_('File successfully uploaded'); $return['file'] = $file; } catch (Exception $e) { echo json_encode(array('error' => $e->getMessage())); } } echo json_encode($return); } }