note 86112 added to function.rmdir

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
here is a little improved 'removing' function with DirectoryIterator:

note for PHP on windows: if using the iterator and recursively removing dirs and files, u need to unset() before leaving/continue the foreach! ( permission denied problem...)

<?php

function removeRessource( $_target ) {
    $_target = realpath($_target);
    
    //file?
    if( is_file($_target) ) {
        if( is_writable($_target) ) {
            if( @unlink($_target) ) {
                return true;
            }
        }
        
        return false;
    }
    	
    //dir?
    if( is_dir($_target) ) {
        if( is_writeable($_target) ) {
            foreach( new DirectoryIterator($_target) as $_res ) {
                if( $_res->isDot() ) {
                    unset($_res);
                    continue;
                }
					
                if( $_res->isFile() ) {
                    removeRessource( $_res->getPathName() );
                } elseif( $_res->isDir() ) {
                    removeRessource( $_res->getRealPath() );
                }
                
                unset($_res);
            }
            		
            if( @rmdir($_target) ) {
                return true;
            }
        }
        
        return false;
    }
}
?
----
Server IP: 212.124.37.9
Probable Submitter: 80.228.208.231
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit        -- https://master.php.net/note/edit/86112
Del: integrated  -- https://master.php.net/note/delete/86112/integrated
Del: useless     -- https://master.php.net/note/delete/86112/useless
Del: bad code    -- https://master.php.net/note/delete/86112/bad+code
Del: spam        -- https://master.php.net/note/delete/86112/spam
Del: non-english -- https://master.php.net/note/delete/86112/non-english
Del: in docs     -- https://master.php.net/note/delete/86112/in+docs
Del: other reasons-- https://master.php.net/note/delete/86112
Reject      -- https://master.php.net/note/reject/86112
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.