Skip to content

Commit

Permalink
完善多文件上传
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Oct 28, 2022
1 parent a0f21a2 commit 00f2e75
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/concerns/InteractsWithHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function preloadHttp()
$app->instance('route', $newRoute);
});
}

$middleware = clone $this->app->middleware;
$this->modifyProperty($middleware, null);
unset($this->app->middleware);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 00f2e75

Please sign in to comment.