1 2 3 | <?php unlink( "images/test.jpg" ); // ฟังก์ชั่นลบไฟล์ที่มี พาธ images/test.jpg ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php function fulldelete( $location ) { if ( is_dir ( $location )) { $currdir = opendir( $location ); while ( $file = readdir( $currdir )) { if ( $file <> ".." && $file <> "." ) { $fullfile = $location . "/" . $file ; if ( is_dir ( $fullfile )) { if (!fulldelete( $fullfile )) { return false; } } else { if (!unlink( $fullfile )) { return false; } } } } closedir ( $currdir ); if (! rmdir ( $location )) { return false; } } else { if (!unlink( $location )) { return false; } } return true; } ?> |
1 2 3 | <?php fulldelete( $location ); // กำหนด $location เป็นตำแหน่งไฟล์หรือโฟลเดอร์ ?> |