In what situations would using $_SERVER["SERVER_NAME"] and $_SERVER["SCRIPT_NAME"] to construct the file path result in unexpected or incorrect outputs?

Using $_SERVER["SERVER_NAME"] and $_SERVER["SCRIPT_NAME"] to construct file paths can result in unexpected or incorrect outputs when the server configuration or request handling is not standard. To ensure accurate file paths, it's recommended to use $_SERVER["DOCUMENT_ROOT"] instead, as it provides the absolute path to the web server's root directory.

$filePath = $_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"];
echo $filePath;