What are the common pitfalls when trying to create directories using PHP?

Common pitfalls when trying to create directories using PHP include incorrect file permissions, invalid directory paths, and not checking if the directory already exists before attempting to create it. To avoid these issues, always ensure that the directory path is correct, set appropriate file permissions, and use the `mkdir()` function with the `recursive` parameter set to `true` to create nested directories if needed.

$directory = "/path/to/directory";
if (!file_exists($directory)) {
    mkdir($directory, 0777, true);
    echo "Directory created successfully!";
} else {
    echo "Directory already exists!";
}