]>
Commit | Line | Data |
---|---|---|
d8c46ff7 | 1 | <?php |
f0794be3 GJ |
2 | /** |
3 | * Uguu | |
4 | * | |
5 | * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se> | |
6 | * | |
7 | * This program is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
f0794be3 GJ |
21 | require_once __DIR__ . '/../vendor/autoload.php'; |
22 | ||
8be20956 GJ |
23 | use Pomf\Uguu\Classes\Upload; |
24 | use Pomf\Uguu\Classes\Response; | |
f0794be3 | 25 | |
8be20956 GJ |
26 | function handleFile(string $outputFormat, array $files) |
27 | { | |
28 | $upload = new Upload($outputFormat); | |
29 | $files = $upload->reFiles($files); | |
30 | try { | |
31 | $upload->fingerPrint(count($files)); | |
32 | $res = []; | |
33 | foreach ($files as $ignored) { | |
34 | $res[] = $upload->uploadFile(); | |
35 | } | |
36 | if (!empty($res)) { | |
37 | $upload->send($res); | |
38 | } | |
39 | } catch (Exception $e) { | |
40 | $upload->error($e->getCode(), $e->getMessage()); | |
41 | } | |
f0794be3 | 42 | } |
8be20956 GJ |
43 | |
44 | if (!isset($_FILES['files']) or empty($_FILES['files'])) { | |
45 | $response = new Response('json'); | |
46 | $response->error(400, 'No input file(s)'); | |
47 | } | |
48 | if (isset($_GET['output']) and !empty($_GET['output'])) { | |
49 | $resType = filter_var($_GET['output'], FILTER_SANITIZE_SPECIAL_CHARS); | |
50 | } else { | |
51 | $resType = 'json'; | |
52 | } | |
53 | handleFile($resType, $_FILES['files']); |