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