diff options
| -rw-r--r-- | public/upload.php | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/public/upload.php b/public/upload.php index 9eecf30..3ef0a0c 100644 --- a/public/upload.php +++ b/public/upload.php @@ -118,7 +118,16 @@ try { throw new RuntimeException("Failed to save the file. Try again later."); } - json_response($file_data, null, 201); + if ($_SERVER['HTTP_ACCEPT'] == 'application/json') { + json_response($file_data, null, 201); + } else { + header("Location: /{$file_data['id']}.{$file_data['extension']}"); + } } catch (RuntimeException $e) { - json_response(null, $e->getMessage(), 400); + if ($_SERVER['HTTP_ACCEPT'] == 'application/json') { + json_response(null, $e->getMessage(), 400); + } else { + http_response_code(400); + echo $e->getMessage(); + } }
\ No newline at end of file |
