file($file['tmp_name']), FILE_ACCEPTED_MIME_TYPES, true)) { json_response(null, 'Invalid file format', 400); exit(); } $file_id = generate_random_char_sequence(FILE_ID_CHARACTERS, FILE_ID_LENGTH); if (!move_uploaded_file($file['tmp_name'], FILE_DIRECTORY . sprintf('/%s.%s', $file_id, $file_ext))) { json_response(null, 'Failed to save the file. Try again later.', 500); exit(); } json_response([ 'id' => $file_id, 'ext' => $file_ext, 'mime' => FILE_ACCEPTED_MIME_TYPES[$file_ext] ], null, 201);