Delete or Remove all files and folders in a directory‎

If you want to delete everything from folder (including subfolders) use this function.

function removeDir( $dir )
{
   if ( is_dir( $dir ) ) {
      $objects = scandir( $dir );
      foreach ( $objects as $object ) {
         if ( $object != "." && $object != ".." ) {
            if ( filetype( $dir . "/" . $object ) == "dir" ) {
               rrmdir( $dir . "/" . $object );
            }
            else {
               unlink( $dir . "/" . $object );
            }
         }
      }
 
      reset( $objects );
      rmdir( $dir );
   }
 
   return true;
}
 
removeDir( '/foo/' );

Tags

No tag here.

Recommended pages

Number Format...

Format a number with grouped thousands......

URL Checker...

This function check if an url is valid or not. function is_valid_url($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); }...

Gregorian to Persian Date Convertor...

Gregorian to Persian Date Convertor....

Detect file extension function...

This function is used to find the file extension also you can use pathinfo() function for get information about a file path. function ext($file_name) { return substr($file_name, strrpos($fi...