delete a folder with content using php


function remove_temp($dirname = '.')
{
if (is_dir($dirname))
{
if ($handle = @opendir($dirname))
{
while (($file = readdir($handle)) !== false)
{
if ($file != "." && $file != "..")
{
$fullpath = $dirname . '/' . $file;
if (is_dir($fullpath))
{
remove_temp($fullpath);
@rmdir($fullpath);
}
else
{
@unlink($fullpath);
}
}
}
closedir($handle);
}
rmdir($dirname);
}
}
remove_temp('path/to/delete/folder/here/');

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s