From: noscript at uni dot de
Operating system: Windows and Unix both
PHP version: 4.3.7
PHP Bug Type: *Directory/Filesystem functions
Bug description: No access for deleting files after building recursive array
Description:
------------
This code should read a directory with all subfolders and files. After
that it should delete the whole dir. But it doesnt work. It comes with a
lot of permission denied messages. But Files are deletable and with
unlink() it works in another test script without the array building. BTW:
closedir returns false but I dont know why...
Reproduce code:
---------------
<?php
function readdeldirs($dir)
{
if($dir[strlen($dir)-1]!='/')$dir.='/';
$dirs=Array();
$dh=opendir($dir);
while(gettype($datei=readdir($dh))!='boolean')
{
if($datei!='.' && $datei!='..')
{
if(is_dir($dir.$datei))$dirs=array_merge($dirs,readdeldirs($dir.$datei));
$dirs[]=$dir.$datei;
}
}
closedir($dh);
return $dirs;
}
function deltree($dir)
{
$load=readdeldirs($dir);
array_multisort($load, SORT_DESC);
foreach($load as $del)
{
if(is_dir($del))
{
rmdir($del);
}
if(is_file($del))
{
unlink($file);
}
}
rmdir($dir);
}
deltree('download');
Expected result:
----------------
Whole directory with all contents is deleted
Actual result:
--------------
Whole of Permission denied messages
--
Edit bug report at http://bugs.php.net/?id=29062&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29062&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29062&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29062&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29062&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29062&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29062&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29062&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29062&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29062&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29062&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29062&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29062&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29062&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29062&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29062&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29062&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29062&r=float