summaryrefslogtreecommitdiff
path: root/tests/http/upload.php
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-23 14:00:08 +0300
committerWolfy-J <[email protected]>2018-09-23 14:00:08 +0300
commitf7d64d8e8592951ed5a0f0b06db608bc73786ea2 (patch)
tree1bdef1618288221495f1f38bb528e71cca907e2e /tests/http/upload.php
parent4815ebb760672c7fa541c941d7f47cd316656020 (diff)
- new directory structure
- singular exception - starting exception deprecation
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