X-Git-Url: https://jfr.im/git/uguu.git/blobdiff_plain/841230530d86507612d75d3b565c30ee7c8e3109..HEAD:/src/static/php/upload.php diff --git a/src/static/php/upload.php b/src/static/php/upload.php index c4f25a6..ea7a427 100644 --- a/src/static/php/upload.php +++ b/src/static/php/upload.php @@ -1,8 +1,9 @@ + * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,13 +18,29 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - require_once __DIR__ . '/../vendor/autoload.php'; - use Pomf\Uguu\Classes\UploadGateway; + use Pomf\Uguu\Classes\Upload; + use Pomf\Uguu\Classes\Response; + + function handleFiles(string $outputFormat, array $files):void + { + $upload = new Upload($outputFormat); + $files = $upload->reFiles($files); + $fCount = count($files); + $upload->fingerPrint($fCount); + $res = []; + foreach ($files as $f) { + $res[] = $upload->uploadFile($f); + } + if (!empty($res)) { + $upload->send($res); + } + } - try { - (new UploadGateway())->handleFile($_GET['output'], $_FILES['files']); - } catch (Exception $e) { - throw new Exception($e->getMessage(), 500); + $response = new Response('json'); + $resType = (isset($_GET['output']) and !empty($_GET['output'])) ? strtolower(preg_replace('/[^a-zA-Z]/', '', $_GET['output'])) : 'json'; + if (!isset($_FILES['files']) or empty($_FILES['files'])) { + $response->error(400, 'No input file(s)'); } + handleFiles($resType, $_FILES['files']);