PHP : How to remove a folder and its content?

If you are using PHP then you can use this function.

/*

@params

$dir – the full directory path of the FOLDER you want to delete

$DeleteMe – if you want to delete the said FOLDER or not.

*/

function rmdir_r ( $dir, $DeleteMe = TRUE ){

if ( ! $dh = @opendir ( $dir ) ) return;
while ( false !== ( $obj = readdir ( $dh ) ) )
{
if ( $obj == ‘.’ || $obj == ‘..’) continue;
if ( ! @unlink ( $dir . ‘/’ . $obj ) ) $this->rmdir_r ( $dir . ‘/’ . $obj, true );
}

closedir ( $dh );
if ( $DeleteMe )
{
@rmdir ( $dir );
}

}

3 thoughts on “PHP : How to remove a folder and its content?

  1. Pingback: lorazepam dosages

  2. Pingback: Bronzefiguren

  3. Pingback: programand0.info

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.