0

I create in my project a directory with subdirectories and files. After I do my duty with files content I want to delete the entire folder(all the subdirectories, files and main directory).

I use ZF2 framework and this is my function:

    public function recursiveRemoveDirectory($directory) {
        foreach(glob("{$directory}/*") as $file) {
            if(is_dir($file)) {
                $this->recursiveRemoveDirectory($file);
            } else {
                unlink($file);
            }
        }

        rmdir($directory);
    }

and I call this function in this way:

$this->recursiveRemoveDirectory($dirPath);

My function erase all contents(subdirectories and files) of the directory but not the directory.

I see that already exist questions on this topic, but I didn't find the solution.

Andreea
  • 151
  • 1
  • 3
  • 12

1 Answers1

1

I think there Delete directory with files in it? you can find all ways to delete folder using php.

In addition I recommend you this library for file operations: https://github.com/thephpleague/flysystem

It's incapsulate all thing that you need and well documented here: http://flysystem.thephpleague.com/api/

Community
  • 1
  • 1
marv255
  • 808
  • 6
  • 19