public function upload() { header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Credentials: true"); header("Access-Control-Allow-Methods:POST, GET, PUT, DELETE, OPTIONS"); header("Access-Control-Allow-Headers:X-FILENAME"); if (strtolower($this->get_method()) == "options") { exit; } if (!($tmp = $this->_get_tmp_file())) { $this->send_response(400, NULL, Kohana::lang('graph.upload_file_empty')); } //文件超过64M if ($tmp['length'] > Kohana::config('graph.file_max_size')) { $this->send_response(400, NULL, Kohana::lang('graph.upload_file_max')); } //未登陆处理 if ($this->un_oauth_check) { $guid = isset($_GET['guid']) ? $_GET['guid'] : ''; $client_id = isset($_GET['client_id']) ? (int) $_GET['client_id'] : 0; if (empty($guid)) { $this->send_response(400, NULL, Kohana::lang('graph.guid_empty')); } // if (! $time = $this->model->add_contact_data($tmp['file'], $guid)) // { // $this->send_response(400, NULL, Kohana::lang('graph.upload_file_error')); // } if ($md5 = $this->model->upload($tmp['file'])) { $this->model->add_device_history($md5, $guid, $client_id); $this->send_response(200, array('guid' => $guid, 'time' => time()), '', FALSE); } else { $this->send_response(400, NULL, Kohana::lang('graph.upload_file_fail')); } } else { //已登陆处理 $reason = isset($_GET['reason']) ? $_GET['reason'] : ''; if (empty($reason)) { $this->send_response(400, NULL, Kohana::lang('graph.reason_empty')); } if ($md5 = $this->model->upload($tmp['file'])) { $url = url::base(FALSE) . 'graph/download/' . $md5; if ($this->model->update($this->user_id, $url, $reason, $this->appid, $this->device_id, $this->source)) { $this->send_response(200, NULL, '', FALSE); } else { $this->send_response(500, NULL, Kohana::lang('graph.operation_fail')); } } else { $this->send_response(400, NULL, Kohana::lang('graph.upload_file_fail')); } } }