file('file'); $type = $request->get('type'); $setting = $this->type2file($type); if (!count($setting)) { $this->response->errorBadRequest('请求错误'); return ''; } $path = $handler->save($file, $setting['folder'], $setting['disk'], $setting['file_prefix']); $re = Upload::create([ 'path' => $path, 'disk' => $setting['disk'], 'is_use' => Upload::USE_NO, 'url' => path_to_url($path, $setting['disk']) ]); return $this->response->item($re, UploadTransformer::class); } catch (\Exception $exception) { return $this->errorBadRequest('上传失败'); } } /** * 根据不同的类型上传到不同的目录 * @param $type * @return array * User: Mead */ protected function type2file($type) { $data = [ 'folder' => '', 'disk' => 'qiniu', 'file_prefix' => $type ]; switch ($type) { case 'trouble': $data['folder'] .= 'trouble'; return $data; break; } return []; } }