Here is a copy and paste type code for "How to delete folder with files in php?" In php, there is no any default inbuilt function for deleting for together with its files contents. i used to delete first the file by unlink("folder_path") and the after us function rmdir("folder_path") to remove empty folder. i am using this code in my websites. if any doubt or suggestion, please comment me below.
Copy and paste code for : How to delete folder with files in php? is written bellow:
<?php
//START- delete FOLDER-php delete function that deals with directories recursively
function deleteDir($folder_path) {
//Get a list of file paths using the glob function.
$fileList = glob($folder_path."/*");
//Loop through the array that glob returned.
foreach($fileList as $filename){
//Simply delete them one by one
unlink($filename);
}
rmdir($folder_path);//finally remove folder which is empty after above process
}
//END- delete FOLDER-php delete function that deals with directories recursively
?>
Comments...
Write Your Comment