Wednesday 16 April 2014

PHP: Unlink All Files Within A Directory, and then Deleting That Directory

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

Example : How to use above function.
$directory = 'www/abc';
recursiveRemoveDirectory($directory)

No comments:

Post a Comment

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...