note 88904 deleted from function.rmdir by danbrown
| From: | danbrown@php.net | Date: | Thu, 12 Feb 2009 18:14:24 +0000 |
| Subject: | note 88904 deleted from function.rmdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150582@lists.php.net to get a copy of this message | ||
Note Submitter: Chris
----
DON'T USE zeke1's FUNCTION ON A WINDOWS SERVER WITHOUT FIRST IMPLEMENTING DIRECTORY
CHECKING
I learned the hard way that if you don't check to see that the path you're deleting is
valid, the script start crawling all over you server deleting stuff. I lost a bunch of stuff on my
development machine, mostly things under C:\Documents and Settings\<my account>
<?php
function rmdir_recurse($path)
{
if(is_dir($path))
{
$path = rtrim($path, '/').'/';
$handle = opendir($path);
while(false !== ($file = readdir($handle)))
{
if($file != '.' and $file != '..' )
{
$fullpath = $path.$file;
if(is_dir($fullpath))
rmdir_recurse($fullpath);
else
unlink($fullpath);
}
}
closedir($handle);
rmdir($path);
}
}
?>