What is the function of ftp_mkdir in PHP and how can it be used to create directories on an FTP server?

The function ftp_mkdir in PHP is used to create a directory on an FTP server. This function takes two parameters: the FTP connection resource and the directory path to be created. To use ftp_mkdir to create directories on an FTP server, you need to establish an FTP connection, then call ftp_mkdir with the connection resource and the desired directory path.

// Establish FTP connection
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

// Check if connection was successful
if (!$conn_id || !$login_result) {
    die('FTP connection failed!');
}

// Create a directory on the FTP server
$directory_path = '/path/to/new/directory';
if (ftp_mkdir($conn_id, $directory_path)) {
    echo 'Directory created successfully!';
} else {
    echo 'Failed to create directory!';
}

// Close FTP connection
ftp_close($conn_id);