From 00f2e75361fda8011bc31db032fc24223553f6e5 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 28 Oct 2022 18:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=9A=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/concerns/InteractsWithHttp.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/concerns/InteractsWithHttp.php b/src/concerns/InteractsWithHttp.php index 5a9dbf5..462649f 100644 --- a/src/concerns/InteractsWithHttp.php +++ b/src/concerns/InteractsWithHttp.php @@ -68,7 +68,7 @@ protected function preloadHttp() $app->instance('route', $newRoute); }); } - + $middleware = clone $this->app->middleware; $this->modifyProperty($middleware, null); unset($this->app->middleware); @@ -177,13 +177,35 @@ protected function prepareRequest(Request $req) ->withGet($req->get ?: []) ->withPost($req->post ?: []) ->withCookie($req->cookie ?: []) - ->withFiles($req->files ?: []) + ->withFiles($this->getFiles($req)) ->withInput($req->rawContent()) ->setBaseUrl($req->server['request_uri']) ->setUrl($req->server['request_uri'] . (!empty($req->server['query_string']) ? '?' . $req->server['query_string'] : '')) ->setPathinfo(ltrim($req->server['path_info'], '/')); } + protected function getFiles(Request $req) + { + if (empty($req->files)) { + return []; + } + + return array_map(function ($file) { + if (!Arr::isAssoc($file)) { + $files = []; + foreach ($file as $f) { + $files['name'][] = $f['name']; + $files['type'][] = $f['type']; + $files['tmp_name'][] = $f['tmp_name']; + $files['error'][] = $f['error']; + $files['size'][] = $f['size']; + } + return $files; + } + return $file; + }, $req->files); + } + protected function setCookie(Response $res, Cookie $cookie) { foreach ($cookie->getCookie() as $name => $val) {