note 88904 added to function.rmdir
| From: | Chris at osu1 dot php dot net | Date: | Thu, 12 Feb 2009 16:59:05 +0000 |
| Subject: | note 88904 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150579@lists.php.net to get a copy of this message | ||
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);
}
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 76.79.4.254
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/88904
Del: integrated -- https://master.php.net/note/delete/88904/integrated
Del: useless -- https://master.php.net/note/delete/88904/useless
Del: bad code -- https://master.php.net/note/delete/88904/bad+code
Del: spam -- https://master.php.net/note/delete/88904/spam
Del: non-english -- https://master.php.net/note/delete/88904/non-english
Del: in docs -- https://master.php.net/note/delete/88904/in+docs
Del: other reasons-- https://master.php.net/note/delete/88904
Reject -- https://master.php.net/note/reject/88904
Search -- https://master.php.net/manage/user-notes.php