/** * Upload images * * @access public * @return Response (json|html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_upload($parent_id = null) { $this->api_accept_formats = array('html', 'json'); $this->api_not_check_csrf = true; $this->controller_common_api(function () use($parent_id) { $upload_type = 'img'; $news = \News\Model_News::check_authority($parent_id); if (!in_array($this->format, array('html', 'json'))) { throw new HttpNotFoundException(); } $thumbnail_size = \Input::post('thumbnail_size'); if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) { throw new \HttpInvalidInputException('Invalid input data'); } $insert_target = \Input::post('insert_target'); $is_insert_body_image = conf('image.isInsertBody', 'news'); $options = \Site_Upload::get_upload_handler_options($this->u->id, true, false, 'nw', $parent_id, true, 'img', $is_insert_body_image); $uploadhandler = new \MyUploadHandler($options, false); \DB::start_transaction(); $files = $uploadhandler->post(false); $files['files'] = \News\Model_NewsImage::save_images($parent_id, $files['files']); \DB::commit_transaction(); $files['upload_type'] = $upload_type; $files['thumbnail_size'] = $thumbnail_size; $files['insert_target'] = $insert_target; $files['model'] = 'news'; $this->set_response_body_api($files, $this->format == 'html' ? 'filetmp/_parts/upload_images' : null); }); }
protected function common_FileTmp_post_upload($upload_type = 'img') { $_method = \Input::param('_method'); if (isset($_method) && $_method === 'DELETE') { return $this->common_FileTmp_delete_upload($upload_type); } $this->api_accept_formats = array('html', 'json'); $this->api_not_check_csrf = true; $this->controller_common_api(function () use($upload_type) { if ($upload_type == 'img') { $thumbnail_size = \Input::post('thumbnail_size'); if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) { throw new HttpInvalidInputException('Invalid input data'); } $insert_target = \Input::post('insert_target'); } $options = Site_Upload::get_upload_handler_options($this->u->id, IS_ADMIN, true, null, 0, true, $upload_type); $uploadhandler = new MyUploadHandler($options, false); $files = $uploadhandler->post(false); $files['upload_type'] = $upload_type; if ($upload_type == 'img') { $files['thumbnail_size'] = $thumbnail_size; $files['insert_target'] = $insert_target; } if ($this->format == 'html') { $this->response_body = View::forge('filetmp/_parts/upload_images', $files)->render(); } else { $this->response_body = $files; } return $this->response_body; }); }