How can the correct path be determined when creating directories in PHP to avoid permission errors?

When creating directories in PHP, it is important to ensure that the correct path is used to avoid permission errors. One way to determine the correct path is by using the `__DIR__` magic constant, which represents the directory of the current file. By appending the desired directory name to `__DIR__`, you can create directories relative to the current file's location, thus avoiding permission errors.

// Determine the correct path using __DIR__
$directory = __DIR__ . '/new_directory';

// Create the directory if it does not already exist
if (!is_dir($directory)) {
    mkdir($directory, 0777, true);
}