What are the best practices for defining absolute paths in PHP upload scripts?

When defining absolute paths in PHP upload scripts, it is important to use the $_SERVER['DOCUMENT_ROOT'] variable to ensure that the path is consistent across different server environments. This helps avoid path-related errors and ensures that the script can locate the correct directories for file uploads.

$upload_dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';