6 * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 require_once __DIR__
. '/../vendor/autoload.php';
24 use Pomf\Uguu\Classes\Upload
;
25 use Pomf\Uguu\Classes\Response
;
28 * It takes a string and an array as arguments, creates a new Upload object,
29 * calls the reFiles method on the Upload object, calls the fingerPrint method on
30 * the Upload object, calls the uploadFile method on the Upload object,
31 * calls the send method on the Upload object, and calls the error method on the
34 * @param $outputFormat string The format of the output, json or xml
35 * @param $files array The file to be uploaded, which is an array.
39 function handleFile(string $outputFormat, array $files): void
41 $fCount = count($files['size']);
42 $upload = new Upload($outputFormat);
43 $files = $upload->reFiles($files);
45 $upload->fingerPrint($fCount);
47 foreach ($files as $ignored) {
48 $res[] = $upload->uploadFile();
53 } catch (Exception
$e) {
54 $upload->error(500, $e->getMessage());
58 $response = new Response('json');
60 if (!isset($_FILES['files']) or empty($_FILES['files'])) {
61 $response->error(400, 'No input file(s)');
63 if (isset($_GET['output']) and !empty($_GET['output'])) {
64 $resType = strtolower(preg_replace('/[^a-zA-Z]/', '', $_GET['output']));
70 handleFile($resType, $_FILES['files']);
71 } catch (Exception
$e) {
72 $response->error($e->getCode(), $e->getMessage());