note 83126 added to function.rmdir
| From: | ornthalas at NOSPAM dot gmail dot com | Date: | Sun, 11 May 2008 20:25:32 +0000 |
| Subject: | note 83126 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139288@lists.php.net to get a copy of this message | ||
I don't know why, but the glob() function seems to take some time to release file handles.
The consequence is some annoying permission denied on random files.
Using opendir() instead of glob() fixes the problem.
<?php
function rm_recursive($filepath)
{
if (is_dir($filepath) && !is_link($filepath))
{
if ($dh = opendir($filepath))
{
while (($sf = readdir($dh)) !== false)
{
if ($sf == '.' || $sf == '..')
{
continue;
}
if (!rm_recursive($filepath.'/'.$sf))
{
throw new Exception($filepath.'/'.$sf.' could not be deleted.');
}
}
closedir($dh);
}
return rmdir($filepath);
}
return unlink($filepath);
}
?>
Please note that opendir() method is faster than the glob() method.
----
Server IP: 217.174.223.124
Probable Submitter: 82.230.82.47
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/83126
Del: integrated -- https://master.php.net/note/delete/83126/integrated
Del: useless -- https://master.php.net/note/delete/83126/useless
Del: bad code -- https://master.php.net/note/delete/83126/bad+code
Del: spam -- https://master.php.net/note/delete/83126/spam
Del: non-english -- https://master.php.net/note/delete/83126/non-english
Del: in docs -- https://master.php.net/note/delete/83126/in+docs
Del: other reasons-- https://master.php.net/note/delete/83126
Reject -- https://master.php.net/note/reject/83126
Search -- https://master.php.net/manage/user-notes.php