public function cleanDirectory($directoryName, $deleteRootDirectory = false)
    {
        if(is_dir($directoryName)){
            $files = glob( $directoryName . '/*', GLOB_NOSORT );

            foreach( $files as $file )
            {
                $this->cleanDirectory( $file, true );
            }

            if(file_exists($directoryName) && ($deleteRootDirectory == true)) {
                @rmdir( $directoryName );
            }
        } elseif(is_file($directoryName)) {
            @unlink( $directoryName );
        }

        if(file_exists($directoryName)) {
            return true;
        }

        return false;
    }
public function cleanDirectory($directoryName, $deleteRootDirectory = false)
    {
        if(is_dir($directoryName)){
            $files = glob( $directoryName . '/*', GLOB_NOSORT );

            foreach( $files as $file )
            {
                $this->cleanDirectory( $file, true );
            }

            if(file_exists($directoryName) && ($deleteRootDirectory == true)) {
                @rmdir( $directoryName );
            }
        } elseif(is_file($directoryName)) {
            @unlink( $directoryName );
        }

        if(file_exists($directoryName)) {
            return true;
        }

        return false;
    }
public function cleanDirectory ( $ directoryName , $ deleteRootDirectory = false ) { if ( is_dir ( $ directoryName ) ) { $ files = glob ( $ directoryName . '/*' , GLOB_NOSORT ) ; foreach ( $ files as $ file ) { $ this -> cleanDirectory ( $ file , true ) ; } if ( file_exists ( $ directoryName ) && ( $ deleteRootDirectory == true ) ) { @ rmdir ( $ directoryName ) ; } } elseif ( is_file ( $ directoryName ) ) { @ unlink ( $ directoryName ) ; } if ( file_exists ( $ directoryName ) ) { return true ; } return false ; }
To clean a directory

@param string $directoryName

@param bool $deleteRootDirectory

@return bool
To clean a directory