blob: 57526246ddea720e98b8d775c71fd725740f4435 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface
{
$files = $req->getUploadedFiles();
array_walk_recursive($files, function (&$v) {
/**
* @var \Psr\Http\Message\UploadedFileInterface $v
*/
if ($v->getError()) {
$v = [
'name' => $v->getClientFilename(),
'size' => $v->getSize(),
'mime' => $v->getClientMediaType(),
'error' => $v->getError(),
];
} else {
$v = [
'name' => $v->getClientFilename(),
'size' => $v->getSize(),
'mime' => $v->getClientMediaType(),
'error' => $v->getError(),
'sha512' => hash('sha512', $v->getStream()->__toString()),
];
}
});
$resp->getBody()->write(json_encode($files, JSON_UNESCAPED_SLASHES));
return $resp;
}
|