public function uploadAction() { if ($datas = $this->getRequest()->getParams() and !empty($_FILES)) { try { $folder = Core_Model_Directory::getTmpDirectory(true) . '/'; $params = array(); $params['validators'] = array('Extension' => array('jpg', 'png', 'jpeg', 'gif', 'case' => false), 'Size' => array('min' => 100, 'max' => 8000000), 'ImageSize' => array('minwidth' => 20, 'minheight' => 20, 'maxwidth' => 2000, 'maxheight' => 2000)); $params['destination_folder'] = $folder; $params['uniq'] = 1; $params['uniq_prefix'] = ''; //param customs foreach ($params['validators']['ImageSize'] as $key => $value) { if (isset($datas[$key])) { $params['validators']['ImageSize'][$key] = $datas[$key]; } } if (isset($datas['uniq_prefix'])) { $params['uniq_prefix'] = $datas['uniq_prefix']; } if (isset($datas['desired_name']) && $datas['desired_name'] != '') { $params['desired_name'] = $datas['desired_name']; } $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->upload($params); $image_sizes = getimagesize(Core_Model_Directory::getTmpDirectory(true) . '/' . $file); $datas = array('success' => 1, 'files' => $file, 'source_width' => $image_sizes[0], 'source_height' => $image_sizes[1], 'message_success' => 'Envoi réussi', 'message_button' => 0, 'message_timeout' => 2); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function validatecropAction() { if ($datas = $this->getRequest()->getPost()) { try { $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); $datas = array('success' => 1, 'file' => $file, 'message_success' => 'Enregistrement réussi', 'message_button' => 0, 'message_timeout' => 2); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function validateAction() { if ($datas = $this->getRequest()->getPost()) { try { $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); $datas = array('success' => 1, 'file' => $file, 'message_success' => $this->_('Info successfully saved'), 'message_button' => 0, 'message_timeout' => 2); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($datas); } }
public function saveAction() { if ($datas = $this->getRequest()->getPost()) { try { $logo_relative_path = '/logo/'; $folder = Application_Model_Application::getBaseImagePath() . $logo_relative_path; $datas['dest_folder'] = $folder; $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); $this->_application->setLogo($logo_relative_path . $file); $this->_application->save(); $datas = array('success' => 1, 'file' => Application_Model_Application::getImagePath() . $logo_relative_path . $file); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function savestartupAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); $relative_path = '/' . $application->getId() . '/startup_image/'; $filetype = $this->getRequest()->getParam('filetype'); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $datas['dest_folder'] = $folder; $datas['new_name'] = $datas['file']; $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); $url = ""; $format = pathinfo($file, PATHINFO_EXTENSION); //Startup images must be forced to png if ($format != "png") { switch ($format) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($folder . $file); break; case 'gif': $image = imagecreatefromgif($folder . $file); break; } $new_name = uniqid() . ".png"; imagepng($image, $folder . $new_name); $file = $new_name; } if ($filetype == "standard") { $application->setData("startup_image", $relative_path . $file); } else { $application->setData("startup_image_" . $filetype, $relative_path . $file); } $application->save(); $datas = array('success' => 1, 'file' => $application->getStartupImageUrl($filetype)); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function savehomepageAction() { if ($datas = $this->getRequest()->getPost()) { try { $filetype = $this->getRequest()->getParam('filetype'); $folder = Application_Model_Application::getBaseImagePath() . $this->_homepage_relative_path . $filetype . '/'; $datas['dest_folder'] = $folder; $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); if ($filetype == 'bg') { $this->getApplication()->setHomepageBackgroundImageRetinaLink($this->_homepage_relative_path . 'bg' . '/' . $file); } else { $this->getApplication()->setHomepageBackgroundImageLink($this->_homepage_relative_path . 'bg_lowres' . '/' . $file); } $this->getApplication()->save(); $datas = array('success' => 1, 'file' => $file); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function savestartupAction() { if ($datas = $this->getRequest()->getPost()) { try { $relative_path = '/startup_image/'; $filetype = $this->getRequest()->getParam('filetype'); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $datas['dest_folder'] = $folder; $datas['new_name'] = $datas['file']; $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); if ($filetype == 'retina') { $this->getApplication()->setStartupImageRetina($relative_path . '/' . $file); } else { $this->getApplication()->setStartupImage($relative_path . '/' . $file); } $this->getApplication()->save(); $datas = array('success' => 1, 'file' => $file); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function setbackgroundimageAction() { if ($datas = $this->getRequest()->getPost()) { try { $option_value = new Application_Model_Option_Value(); $option_value->find($datas['option_id']); if (!$option_value->getId()) { throw new Exception($this->_("An error occurred while saving your picture. Please try againg later.")); } // Récupère l'option $option = new Application_Model_Option(); $option->find($option_value->getOptionId()); $save_path = '/feature/' . $option->getId() . '/background/'; $relative_path = Application_Model_Application::getImagePath() . $save_path; $folder = Application_Model_Application::getBaseImagePath() . $save_path; $datas['dest_folder'] = $folder; $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); $option_value->setBackgroundImage($save_path . $file)->save(); $datas = array('success' => 1, 'file' => $relative_path . $file); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function cropAction() { if ($datas = $this->getRequest()->getPost()) { try { $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); $datas = array('success' => 1, 'file' => $file); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function savesliderimagesAction() { if ($datas = $this->getRequest()->getPost()) { try { $url = ""; $image_id = null; $application = $this->getApplication(); $relative_path = '/' . $application->getId() . '/slider_images/'; $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $datas['dest_folder'] = $folder; $uploader = new Core_Model_Lib_Uploader(); if ($file = $uploader->savecrop($datas)) { $url = Application_Model_Application::getImagePath() . $relative_path . $file; $library = new Media_Model_Library(); $library->find($application->getHomepageSliderLibraryId()); if (!$library->getId()) { $library->setName('homepage_slider_' . $application->getId())->save(); $application->setHomepageSliderLibraryId($library->getId())->save(); } $image = new Media_Model_Library_Image(); $image->setLibraryId($library->getId())->setLink($url)->setAppId($application->getId())->save(); $image_id = $image->getId(); } $datas = array('success' => 1, 'file' => array("id" => $image_id, "url" => $url)); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); } }
public function uploadAction() { try { if (empty($_FILES) || empty($_FILES['file']['name'])) { throw new Exception("No file has been sent"); } $base_path = Core_Model_Directory::getTmpDirectory(true); if (!is_dir($base_path)) { mkdir($base_path, 0777, true); } $params = array("validators" => array("Size" => array("min" => 100, "max" => 8000000)), "destination_folder" => $base_path, "uniq" => 1); $sizes = array("minwidth", "minheight", "maxwidth", "maxheight"); foreach ($sizes as $key) { if ($size = $this->getRequest()->getPost($key)) { $params["validators"]["ImageSize"][$key] = $size; } } $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->upload($params); if ($file) { $this->_sendHtml(array("success" => 1, "message" => $this->_("Your image has been successfully saved"), "filename" => $file)); } else { $message = $this->_("An error occurred during the process. Please try again later."); throw new Exception($message); } } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); $this->_sendHtml($data); } }