What potential issues can arise when using mkdir() in PHP to create directories, especially when moving the script to a different server?

When using mkdir() in PHP to create directories, potential issues can arise if the directory path is not specified correctly or if the script does not have the necessary permissions to create directories. To ensure portability when moving the script to a different server, it is advisable to use absolute paths instead of relative paths when creating directories.

// Specify absolute path for directory creation
$directory = '/path/to/directory';

// Check if directory already exists
if (!is_dir($directory)) {
    // Create directory with necessary permissions
    mkdir($directory, 0755, true);
}