What are common issues with using relative paths in PHP opendir function?

When using relative paths in the PHP opendir function, common issues can arise due to the script not being able to correctly resolve the path. To solve this issue, it is recommended to use the __DIR__ constant along with the relative path to ensure that the correct directory is being accessed.

$directory = __DIR__ . '/relative/path/to/directory';

if ($handle = opendir($directory)) {
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";
    }
    closedir($handle);
}