$maxBytes) json_err('File exceeds 5 MB limit'); $ext = pathinfo($file['name'], PATHINFO_EXTENSION); $filename = uuid() . '.' . strtolower($ext); $uploadDir= __DIR__ . '/../../uploads/' . $context . '/'; if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true); $dest = $uploadDir . $filename; if (!move_uploaded_file($file['tmp_name'], $dest)) json_err('Upload failed', 500); // Build public URL — adjust the base URL to match your Hostinger domain. $baseUrl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; $url = $baseUrl . '/uploads/' . $context . '/' . $filename; json_ok(['url' => $url]);