What are the best practices for specifying file paths in PHP to avoid errors?

When specifying file paths in PHP, it is important to use the correct directory separator (either '/' or '\') based on the operating system. To avoid errors, it is recommended to use the PHP constant `DIRECTORY_SEPARATOR` to dynamically generate file paths. Additionally, it is good practice to use the `__DIR__` magic constant to reference the current directory and build paths relative to it.

// Specify file path using DIRECTORY_SEPARATOR and __DIR__
$filePath = __DIR__ . DIRECTORY_SEPARATOR . 'folder' . DIRECTORY_SEPARATOR . 'file.txt';