PHP Delete ALL files in directory


define(’PATH’, ‘/www/public/images/’);
 
function destroy($dir) {
    $mydir = opendir($dir);
    while(false !== ($file = readdir($mydir))) {
        if($file != “.” && $file != “..”) {
            chmod($dir.$file, 0777);
            if(is_dir($dir.$file)) {
                chdir(’.');
                destroy($dir.$file.’/');
                rmdir($dir.$file) or DIE(”couldn’t delete $dir$file
“);
            }
            else
                unlink($dir.$file) or DIE(”couldn’t delete $dir$file
“);
        }
    }
    closedir($mydir);
}
destroy(PATH);

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
duivesteyn.com.au nameservers
Custom Function to Mediawiki

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

You must be logged in to post a comment. Click here to login.

Reader Comments

Be the first to leave a comment!