summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-03-18 02:43:15 +0500
committerilotterytea <iltsu@alright.party>2025-03-18 02:43:15 +0500
commiteacbea32efb110363e461c344100ca9511a97630 (patch)
treee74d86289698ebb376a199251803f61a9cab70d2 /public
parentad1f0a370d432701bc5fe4eb6fa1fb23f94c1293 (diff)
upd: json responses
Diffstat (limited to 'public')
-rw-r--r--public/upload.php17
1 files changed, 10 insertions, 7 deletions
diff --git a/public/upload.php b/public/upload.php
index 2ff9e96..2952315 100644
--- a/public/upload.php
+++ b/public/upload.php
@@ -1,21 +1,24 @@
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php';
if (!isset($_FILES['file'])) {
- http_response_code(400);
- exit("No 'file' specified!");
+ json_response(null, "No 'file' specified!", 400);
+ exit();
}
if (!is_dir(FILE_DIRECTORY) && !mkdir(FILE_DIRECTORY, 0777, true)) {
- http_response_code(500);
- exit("Failed to create a directory for user files");
+ json_response(null, 'Failed to create a directory for user files', 500);
+ exit();
}
$file = $_FILES['file'];
if (!move_uploaded_file($file['tmp_name'], FILE_DIRECTORY . sprintf('/%s', $file['name']))) {
- http_response_code(500);
- exit("Failed to save the file. Try again later.");
+ json_response(null, 'Failed to save the file. Try again later.', 500);
+ exit();
}
-header(sprintf('Location: /%s', $file['name'])); \ No newline at end of file
+json_response([
+ 'id' => $file['name']
+], null, 201); \ No newline at end of file