note 77240 added to function.readdir
| From: | dot) | Date: | Tue, 21 Aug 2007 11:09:55 +0000 |
| Subject: | note 77240 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129667@lists.php.net to get a copy of this message | ||
The following code is a bit nasty, it can be used to remove all files generated by apache.
You're not a root user on a system, but you sometimes need to remove all files generated by
apache in a certain directory. You may use this after replacing 'bbs' at the bottom with
'directory' you want.
It tries to remove all files in a directory, but it can't unless it has an ownership. it
doesn't check the ownership or permission.
<?php
function remove($dirname = '.')
{
if (is_dir($dirname))
{
echo "$dirname is a directory.<br />";
if ($handle = @opendir($dirname))
{
while (($file = readdir($handle)) !== false)
{
if ($file != "." && $file != "..")
{
echo "$file<br />";
$fullpath = $dirname . '/' . $file;
if (is_dir($fullpath))
{
remove($fullpath);
@rmdir($fullpath);
}
else
{
@unlink($fullpath);
}
}
}
closedir($handle);
}
}
}
remove('bbs');
?>
----
Server IP: 211.43.210.124
Probable Submitter: 203.253.22.113
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/77240
Del: integrated -- https://master.php.net/note/delete/77240/integrated
Del: useless -- https://master.php.net/note/delete/77240/useless
Del: bad code -- https://master.php.net/note/delete/77240/bad+code
Del: spam -- https://master.php.net/note/delete/77240/spam
Del: non-english -- https://master.php.net/note/delete/77240/non-english
Del: in docs -- https://master.php.net/note/delete/77240/in+docs
Del: other reasons-- https://master.php.net/note/delete/77240
Reject -- https://master.php.net/note/reject/77240
Search -- https://master.php.net/manage/user-notes.php