/** * Handler for pictures/video upload interface * @return array */ private function _uploadImages($savePath = null, $resize = true) { $miscConfig = Zend_Registry::get('misc'); if (!$savePath) { //useful if file submited directly to this method $savePath = $this->_getSavePath(); } $this->_uploadHandler->clearValidators()->addValidator('Extension', false, array('jpeg', 'jpg', 'png', 'gif'))->addValidator('ImageSize', false, array('maxwidth' => $miscConfig['imgMaxWidth'], 'maxheight' => $miscConfig['imgMaxWidth'])); if ($this->_checkMime) { $this->_uploadHandler->addValidator(new Validators_MimeType(array('image/gif', 'image/jpeg', 'image/jpg', 'image/png')), false); } $receivePath = $resize ? $savePath . DIRECTORY_SEPARATOR . 'original' : $savePath; if ($this->_uploadHandler->isUploaded() && $this->_uploadHandler->isValid()) { if (!is_dir($receivePath)) { try { Tools_Filesystem_Tools::mkDir($receivePath); } catch (Exceptions_SeotoasterException $e) { error_log($e->getMessage()); } } if (!$this->_uploadHandler->hasFilter('Rename')) { /** * Renaming file if additional field 'name' was submited with file */ $filterChain = new Zend_Filter(); $filterChain->addFilter(new Zend_Filter_StringTrim())->addFilter(new Zend_Filter_StringToLower('UTF-8'))->addFilter(new Zend_Filter_PregReplace(array('match' => '/[^\\w\\d_]+/u', 'replace' => '-'))); // filtering the img name $expFileName = explode('.', $this->getRequest()->getParam('name', false)); $fileExt = array_pop($expFileName); $name = implode($expFileName); $newName = $filterChain->filter($name) . '.' . $fileExt; if (false !== $newName) { $this->_uploadHandler->addFilter('Rename', array('target' => $receivePath . DIRECTORY_SEPARATOR . $newName, 'overwrite' => true)); } else { $this->_uploadHandler->addFilter('Rename', array('target' => $receivePath, 'overwite' => true)); } } if ($this->_uploadHandler->receive()) { $fileInfo = current($this->_uploadHandler->getFileInfo()); } else { return array('error' => true, 'result' => $this->_uploadHandler->getMessages()); } if ($resize) { $status = Tools_Image_Tools::batchResize($fileInfo['tmp_name'], $savePath); } else { $status = true; } if (isset($this->_helper->session->imageQualityPreview)) { unset($this->_helper->session->imageQualityPreview); Tools_Image_Tools::optimizeImage($fileInfo['tmp_name'], self::PREVIEW_IMAGE_OPTIMIZE); } if (isset($this->_helper->session->imageQuality)) { Tools_Image_Tools::optimizeOriginalImage($fileInfo['tmp_name'], $savePath, $this->_helper->session->imageQuality); } return array('error' => $status !== true, 'result' => $status); } return array('error' => true, 'result' => $this->_uploadHandler->getMessages()); }