Skip to content

Instantly share code, notes, and snippets.

@thbighead
Created May 5, 2017 13:29
Show Gist options
  • Save thbighead/6a9c885082899ce54dfce88d4497cf47 to your computer and use it in GitHub Desktop.
Save thbighead/6a9c885082899ce54dfce88d4497cf47 to your computer and use it in GitHub Desktop.
Function to delete a folder and every folders and files inside of it
function recurse_delete($path)
{
if (is_dir($path) === true)
{
$files = array_diff(scandir($path), array('.', '..'));
foreach ($files as $file)
{
recurse_delete(realpath($path) . '/' . $file);
}
return rmdir($path);
}
else if (is_file($path) === true)
{
return unlink($path);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment