What potential pitfalls should be considered when automatically creating folders with PHP?

When automatically creating folders with PHP, potential pitfalls to consider include ensuring proper permissions are set on the folders to prevent unauthorized access, avoiding overwriting existing folders, and handling errors that may occur during the folder creation process.

$folderName = 'new_folder';

// Check if folder already exists
if (!file_exists($folderName)) {
    // Create the folder with proper permissions
    if (!mkdir($folderName, 0777, true)) {
        echo 'Failed to create folder';
    } else {
        echo 'Folder created successfully';
    }
} else {
    echo 'Folder already exists';
}