/** * Method to handle file upload thought XHR2 * On success returns JSON object with image info. * @param $gallery_id string Gallery Id to upload images * @throws CHttpException */ public function actionAjaxUpload($gallery_id = null) { $model = new GalleryPhoto(); $model->gallery_id = $gallery_id; $imageFile = CUploadedFile::getInstanceByName('image'); $model->file_name = $imageFile->getName(); $model->setImage($imageFile->getTempName()); header("Content-Type: application/json"); echo CJSON::encode(array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview())); }
/** * Method to handle file upload thought XHR2 * On success returns JSON object with image info. * @param $gallery_id string Gallery Id to upload images * @throws CHttpException */ public function actionAjaxUpload($gallery_id = null) { $model = new GalleryPhoto(); $model->gallery_id = $gallery_id; $imageFile = CUploadedFile::getInstanceByName('image'); $model->file_name = $imageFile->getName(); $model->save(); $model->setImage($imageFile->getTempName()); // not "application/json", because IE8 trying to save response as a file header("Content-Type: text/html"); echo CJSON::encode(array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview())); if (method_exists(Yii::app()->request, 'setIsAjaxRequest')) { Yii::app()->request->setIsAjaxRequest(true); } }
/** * Method to handle file upload thought XHR2 * On success returns JSON object with image info. * @param $gallery_id string Gallery Id to upload images * @throws CHttpException */ public function actionAjaxUpload($gallery_id = null) { $model = new GalleryPhoto(); $model->gallery_id = $gallery_id; $imageFile = CUploadedFile::getInstanceByName('image'); $model->file_name = $imageFile->getName(); $model->thumb_ext = $model->getExtensionFromMime($imageFile); $model->save(); if (Yii::app()->params['LIGHTSPEED_MT'] == '1') { $model->setS3Image($imageFile); } else { $model->setImage($imageFile); } header("Content-Type: application/json"); echo CJSON::encode(array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview())); }
public function actionAjaxUploadCustom($gallery_id = null, $image_id = null) { if (Yii::app()->getRequest()->getIsPostRequest()) { $model = new GalleryPhoto(); $model->gallery_id = $gallery_id; if (isset($_POST['GalleryPhoto'])) { $model->attributes = $_POST['GalleryPhoto']; } $imageFile = dirname(__FILE__) . '/../../www/distributer_gallery/' . $image_id . '.png'; $model->file_name = $image_id . '.png'; $model->save(); $model->setImage($imageFile); header("Content-Type: application/json"); echo CJSON::encode(array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview())); } else { throw new CHttpException(404); } }