]> jfr.im git - uguu.git/blobdiff - src/static/php/upload.php
replace name generator method
[uguu.git] / src / static / php / upload.php
old mode 100644 (file)
new mode 100755 (executable)
index a2cb519..9fd5153
@@ -1,9 +1,18 @@
 <?php
-
-/**
+/*
  * Uguu
  *
- * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
  *
  * 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
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-error_reporting(0);
-
 require_once __DIR__ . '/../vendor/autoload.php';
+use Pomf\Uguu\Classes\Upload;
+use Pomf\Uguu\Classes\Response;
 
-use Pomf\Uguu\UploadGateway;
+function handleFiles(string $outputFormat, array $files):void
+{
+    $upload = new Upload($outputFormat);
+    $files = $upload->reFiles($files);
+    $fCount = count($files);
+    $upload->fingerPrint($fCount);
+    $res = [];
+    $i = 0;
+    while ($i < $fCount) {
+        $res[] = $upload->uploadFile();
+        $i++;
+    }
+    if (!empty($res)) {
+        $upload->send($res);
+    }
+}
 
-try {
-    (new UploadGateway())->handleFile($_GET['output'], $_FILES['files']);
-} catch (Exception $e) {
-    throw new Exception($e->getMessage(), 500);
+$resType = (isset($_GET['output']) and !empty($_GET['output'])) ? strtolower(preg_replace('/[^a-zA-Z]/', '', $_GET['output'])) : 'json';
+$response = new Response($resType);
+if (!isset($_FILES['files']) or empty($_FILES['files'])) {
+    $response->error(400, 'No input file(s)');
 }
+handleFiles($resType, $_FILES['files']);