In what situations would it be advisable to create folders using PHP code instead of relying on FTP programs for setting permissions?

Creating folders using PHP code may be advisable in situations where you need to dynamically create folders based on user input or specific conditions within your application. This allows you to set permissions on the folders programmatically, ensuring that the correct permissions are always applied. Additionally, using PHP code to create folders gives you more control and flexibility over the folder creation process compared to relying on FTP programs.

$folderName = "new_folder";
$folderPath = "/path/to/your/directory/" . $folderName;

if (!file_exists($folderPath)) {
    mkdir($folderPath, 0755); // Set folder permissions to 0755
    echo "Folder created successfully.";
} else {
    echo "Folder already exists.";
}