/** * 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); }); }
public static function get_file_objects($file_tmps, $member_id, $is_admin = false, $type = 'img') { $options = Site_Upload::get_upload_handler_options($member_id, $is_admin, true, null, 0, true, $type); $uploadhandler = new MyUploadHandler($options, false); return $uploadhandler->get_file_objects_from_file_tmps($file_tmps, $type); }
protected function common_FileTmp_delete_upload($upload_type = 'img') { $this->controller_common_api(function () use($upload_type) { $id = (int) Input::post('id'); $file_tmp = Model_FileTmp::check_authority($id, $this->u->id, null, 'member_id', IS_ADMIN ? 1 : 0); $options = Site_Upload::get_upload_handler_options($this->u->id, IS_ADMIN, true, null, 0, true, $upload_type); $uploadhandler = new MyUploadHandler($options, false); \DB::start_transaction(); $this->response_body = $uploadhandler->delete(false, $file_tmp); \DB::commit_transaction(); return $this->response_body; }); }