[PHP] Hàm xóa tất tần tật

Table of Contents

Hàm xóa tất tần tật bao gồm file đơn, thư mục, thư mục và file!

function delete_files($target) {
    if(is_dir($target)){
        $files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned
        foreach( $files as $file )
        {
            delete_files( $file );
        }
        rmdir( $target );
    } elseif(is_file($target)) {
        unlink( $target );
    }
}
delete_files('D:/websvr/xampp/dtcs2017/uploads/tinh_23082017105147am'); delete_files('D:/websvr/xampp/dtcs2017/uploads/tinh.qpj');
Nguồn: https://dungnt.net/blog/xoa-thu-muc-va-file-trong-mot-thu-muc-php/ -soiqualang.chentreu]]>

Leave a Reply

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