diff options
Diffstat (limited to 'public/upload.php')
| -rw-r--r-- | public/upload.php | 17 |
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 |
