开发者

rmdir in PHP not working on an empty directory

开发者 https://www.devze.com 2023-04-02 03:52 出处:网络
I\'m trying to remove a directory with PHP. I unlink/remove all files/subdirs from the inside out and finally call rmdir on the now empty top directory. Everything goes according to plan until the l

I'm trying to remove a directory with PHP.

I unlink/remove all files/subdirs from the inside out and finally call rmdir on the now empty top directory. Everything goes according to plan until the last call to rmdir. PHP warns that the directory is NOT emtpy and refuses to remove it. But when I look at the directory in the explorer it is empty, after all.

I also tried a well known recursive function with the same result.

The operating system开发者_JAVA百科 is Windows 7 with Xampp and there are no access restrictions for any of the elements in question.

Any ideas?


Can you try this one?

<?php
$handle = opendir($dirpath);
//do whatever you need
closedir($handle)
rmdir($dirpath);
?>


function rrmdir($dir) {
   if (is_dir($dir)) {
     $objects = scandir($dir);
     foreach ($objects as $object) {
       if ($object != "." && $object != "..") {
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
       }
     }
     reset($objects);
     rmdir($dir);
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消