This is a complete tasted just cope-and-paste function code for delete all files and directories in directory in PHP codes.
<?php
//START- Function to delete all files and directories,recursively
//folder address must not end with "/" and must not contain any "." in its address
function delete_all_in_folder($folder_addr) {
$folder_list = glob($folder_addr."/*");
if(count($folder_list)==0){
echo "folder:".$folder_addr."<br>";
rmdir($folder_addr);
}
else{
foreach($folder_list as $filename){
if($filename != null){
$b=stristr($filename,"../");
$b=substr($b,3);
$a=stristr($b,".");
if($a==null){//if it is a folder
delete_all_in_folder($filename);
}
else{
echo "file:".$filename."<br>";
unlink($filename);
}
}
}
echo "folder:".$folder_addr."<br>";
rmdir($folder_addr);
}
}
//END- Function to delete all files and directories,recursively
?>
Posted By :
Mahesh Nigam
(Scientist)
2019-10-13 02:37
See Author's other Published Topics
Peoples
Peoples
Comments...
Write Your Comment