-1

I have a PHP script for deleting a directory. This deletes the target directory but shows an error message if there are more than one file but it still deletes the directory..weird..;Shown error given below:-

Warning: rmdir(uploads/dd4a96d6907035a1d011b9394d779d3c) [function.rmdir]: Directory not empty in /home/.../public_html/deletepost.php on line 21

here's php

<?php

$dir = $row['album_path'];

17     foreach(scandir($dir) as $file) {
18     if ('.' === $file || '..' === $file) continue;
19     if (is_dir("$dir/$file")) rmdir_recursive("$dir/$file");
20     else unlink("$dir/$file");
21     rmdir($dir);
22     }

?>

Am I doing anything wrong with the code?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Shyam3089
  • 459
  • 1
  • 5
  • 20
  • `rmdir();` requires that the directory be empty. You must delete all files within the directory before you can proceed with removing said directory. – jhmckimm Mar 06 '14 at 19:41
  • @ Jordan Hugh McKimm Hi thanks for the answer..I found a solution in this page and it works fine.. http://stackoverflow.com/questions/11267086/php-unlink-all-files-withing-a-directory-and-then-deleting-that-directory – Shyam3089 Mar 06 '14 at 19:56

1 Answers1

0

Here is an example to delete folder without warning in PHP

http://en.kioskea.net/faq/793-php-warning-rmdir-directory-not-empty

Jagadesh K
  • 237
  • 1
  • 13