Ver Mensaje Individual
  #6 (permalink)  
Antiguo 16/03/2011, 17:35
MaxDgy
 
Fecha de Ingreso: enero-2011
Ubicación: Argentina
Mensajes: 80
Antigüedad: 13 años, 3 meses
Puntos: 12
Respuesta: borrar directorio y subdirectorios con archivos dentroto

Borrar un directorio no vacio con PHP

Código PHP:
Ver original
  1. /**
  2.  * Remove a non empty directory
  3.  * @author Cristián Pérez
  4.  * @param string $path Folder Path
  5.  * @return bool
  6.  */
  7. function removeDirectory($path)
  8. {
  9.     $path = rtrim( strval( $path ), '/' ) ;
  10.  
  11.     $d = dir( $path );
  12.  
  13.     if( ! $d )
  14.         return false;
  15.  
  16.     while ( false !== ($current = $d->read()) )
  17.     {
  18.         if( $current === '.' || $current === '..')
  19.             continue;
  20.  
  21.         $file = $d->path . '/' . $current;
  22.  
  23.         if( is_dir($file) )
  24.             removeDirectory($file);
  25.  
  26.         if( is_file($file) )
  27.             unlink($file);
  28.     }
  29.  
  30.     rmdir( $d->path );
  31.     $d->close();
  32.     return true;
  33. }


Fuente:
http://www.cristianperez.com/2010/01...vacio-con-php/

Saludos.