|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-08 13:16 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 UTC |
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