What are some best practices for handling absolute paths in PHP to avoid vulnerabilities?

When handling absolute paths in PHP, it is important to avoid using hard-coded paths as they can lead to vulnerabilities such as directory traversal attacks. Instead, it is recommended to use predefined constants like `__DIR__` or `dirname(__FILE__)` to dynamically generate absolute paths. This ensures that the paths are always accurate and secure.

// Using predefined constants to generate absolute paths
$absolutePath = __DIR__ . '/path/to/file';
// or
$absolutePath = dirname(__FILE__) . '/path/to/file';