Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete dir and content PHP script
11-18-2009, 05:47 AM
Post: #1
Delete dir and content PHP script
This script/function will delete directory and content.
Second parameter is boolean to instruct the function if it should remove the directory or only the content.
Code:
function rmdir_r ( $dir, $DeleteMe = TRUE )
{
    if ( ! $dh = @opendir ( $dir ) ) return;
    while ( false !== ( $obj = readdir ( $dh ) ) )
    {
        if ( $obj == '.' || $obj == '..') continue;
        if ( ! @unlink ( $dir . '/' . $obj ) ) rmdir_r ( $dir . '/' . $obj, true );
    }
    
    closedir ( $dh );
    if ( $DeleteMe )
    {
        @rmdir ( $dir );
    }
}

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: