naeemqaswar
12/30/2018 - 3:31 PM

Delete Files

function deleteFiles($path)
{
    // It it's a file.
    if (is_file($path)) {

        //Attempt to delete it.
        return unlink($path);

    } elseif (is_dir($path)) { // If it's a directory.

        //Get a list of the files in this directory.
        $scan = glob(rtrim($path, '/') . '/*');

        //Loop through the list of files.
        foreach ($scan as $index => $path) {

            //Call our recursive function.
            deleteAll($path);
        }

        return @rmdir($path);    //Remove the directory itself.

    } else {
        return false;
    }
}