public static function rmdir($dir)
    {
        // List the contents of the directory table
        $dir_content = scandir ($dir);
        // Is it a directory?
        if ($dir_content!==false) {
            // For each directory entry
            foreach ($dir_content as &$entry) {
                // Unix symbolic shortcuts, we go
                if (!in_array ($entry, array ('.','..'))) {
                    // We find the path from the beginning
                    $entry = $dir.DIRECTORY_SEPARATOR. $entry;
                    // This entry is not an issue: it clears
                    if (!is_dir($entry)) {
                        unlink ($entry);
                    } else { // This entry is a folder, it again on this issue
                        self::rmdir($entry);
                    }
                }
            }
        }
        // It has erased all entries in the folder, we can now erase
        rmdir ($dir);
    }
public static function rmdir($dir)
    {
        // List the contents of the directory table
        $dir_content = scandir ($dir);
        // Is it a directory?
        if ($dir_content!==false) {
            // For each directory entry
            foreach ($dir_content as &$entry) {
                // Unix symbolic shortcuts, we go
                if (!in_array ($entry, array ('.','..'))) {
                    // We find the path from the beginning
                    $entry = $dir.DIRECTORY_SEPARATOR. $entry;
                    // This entry is not an issue: it clears
                    if (!is_dir($entry)) {
                        unlink ($entry);
                    } else { // This entry is a folder, it again on this issue
                        self::rmdir($entry);
                    }
                }
            }
        }
        // It has erased all entries in the folder, we can now erase
        rmdir ($dir);
    }
public static function rmdir ( $ dir ) { // List the contents of the directory table $ dir_content = scandir ( $ dir ) ; // Is it a directory? if ( $ dir_content !== false ) { // For each directory entry foreach ( $ dir_content as & $ entry ) { // Unix symbolic shortcuts, we go if ( ! in_array ( $ entry , array ( '.' , '..' ) ) ) { // We find the path from the beginning $ entry = $ dir . DIRECTORY_SEPARATOR . $ entry ; // This entry is not an issue: it clears if ( ! is_dir ( $ entry ) ) { unlink ( $ entry ) ; } else { // This entry is a folder, it again on this issue self :: rmdir ( $ entry ) ; } } } } // It has erased all entries in the folder, we can now erase rmdir ( $ dir ) ; }
Borra recursivamente un directorio
@param dir Directorio a borrar
@author http://en.kioskea.net/faq/793-warning-rmdir-directory-not-empty
@version 2015-04-21
Borra recursivamente un directorio