summaryrefslogtreecommitdiff
path: root/tests/http/upload.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/http/upload.php')
-rw-r--r--tests/http/upload.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/http/upload.php b/tests/http/upload.php
new file mode 100644
index 00000000..2f7c0b64
--- /dev/null
+++ b/tests/http/upload.php
@@ -0,0 +1,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(),
+ 'md5' => md5($v->getStream()->__toString()),
+ ];
+ }
+ });
+
+ $resp->getBody()->write(json_encode($files, JSON_UNESCAPED_SLASHES));
+
+ return $resp;
+} \ No newline at end of file