public function upload(array $params = array()) { if ($this->isAvailableFile($_FILES)) { $order = !empty($_POST['order']) ? (int) $_POST['order'] : 0; ini_set('memory_limit', '-1'); if ($id = PHOTO_BOL_PhotoTemporaryService::getInstance()->addTemporaryPhoto($_FILES['file']['tmp_name'], OW::getUser()->getId(), $order)) { $fileUrl = PHOTO_BOL_PhotoTemporaryDao::getInstance()->getTemporaryPhotoUrl($id, 2); $this->returnResponse(array('status' => self::STATUS_SUCCESS, 'fileUrl' => $fileUrl, 'id' => $id)); } else { $this->returnResponse(array('status' => self::STATUS_ERROR, 'msg' => OW::getLanguage()->text('photo', 'no_photo_uploaded'))); } } else { $msg = $this->getErrorMsg($_FILES); $this->returnResponse(array('status' => self::STATUS_ERROR, 'msg' => $msg)); } }
/** * Class constructor * */ private function __construct() { $this->photoTemporaryDao = PHOTO_BOL_PhotoTemporaryDao::getInstance(); }
public static function addTemporaryPhoto($source, $userId, $order) { $tmpPhoto = new PHOTO_BOL_PhotoTemporary(); $tmpPhoto->userId = $userId; $tmpPhoto->addDatetime = time(); $tmpPhoto->hasFullsize = 0; $tmpPhoto->order = $order; $photoTemporaryDao = PHOTO_BOL_PhotoTemporaryDao::getInstance(); $photoTemporaryDao->save($tmpPhoto); $preview = $photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $main = $photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $original = $photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $config = OW::getConfig(); $width = $config->getValue('photo', 'main_image_width'); $height = $config->getValue('photo', 'main_image_height'); $previewWidth = $config->getValue('photo', 'preview_image_width'); $previewHeight = $config->getValue('photo', 'preview_image_height'); try { $image = new UTIL_Image($source); $mainPhoto = $image->resizeImage($width, $height)->saveImage($main); if ((bool) $config->getValue('photo', 'store_fullsize') && $mainPhoto->imageResized()) { $originalImage = new UTIL_Image($source); $res = (int) $config->getValue('photo', 'fullsize_resolution'); $res = $res ? $res : 1024; $originalImage->resizeImage($res, $res)->saveImage($original); $tmpPhoto->hasFullsize = 1; $photoTemporaryDao->save($tmpPhoto); } $mainPhoto->resizeImage($previewWidth, $previewHeight, true)->saveImage($preview); } catch (WideImage_Exception $e) { $photoTemporaryDao->deleteById($tmpPhoto->id); return false; } return true; }