What are common pitfalls when trying to read a directory in PHP when the script is not located in that directory?

When trying to read a directory in PHP from a script that is not located in that directory, a common pitfall is using relative paths instead of absolute paths. To solve this issue, you can use the `dirname(__FILE__)` function to get the absolute path of the current script and then concatenate the directory you want to read.

// Get the absolute path of the current script
$currentDirectory = dirname(__FILE__);

// Specify the directory you want to read
$directoryToRead = $currentDirectory . '/path/to/directory/';

// Read the directory
$files = scandir($directoryToRead);