What is the method to delete a folder in PHP?

In PHP, the method to delete a folder is by using the rmdir() function. This function will remove the specified folder along with all of its files and subfolders. Caution is advised when using this function as the deleted folder and its contents cannot be recovered.

Here is a simple example code showing how to use the rmdir() function to delete a folder.

$folderPath = 'path/to/folder';

if (is_dir($folderPath)) {
    if (rmdir($folderPath)) {
        echo '文件夹删除成功';
    } else {
        echo '文件夹删除失败';
    }
} else {
    echo '文件夹不存在';
}

In the example above, the first step is to check if the folder to be deleted exists, and then use the rmdir() function to delete the folder. If the folder is successfully deleted, it will output “Folder deleted successfully”, otherwise it will output “Folder deletion failed”.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds