w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
PHP Delete all folder content without deleting root folder

Try:

function deleteAll($path)
{
    $dir = dir($path);

    while ($file = $dir->read())
    {
        if ($file == '.' || $file == '..') continue;

        $file = $path . '/' . $file;

        if (is_dir($file))
        {
            deleteAll($file);
            rmdir($file);
        }
        else
        {
            unlink($file);
        }
    }
}

Calling deleteAll('/path/to/FolderFather'); should work as expected.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.