|
Posted by Gleep on 03/25/07 01:03
On Sat, 24 Mar 2007 22:30:52 GMT, "Bill" <no@no.com> wrote:
>Is there a PHP function that will remove a directory that is not empty?
>I am looking for a solution that is easier than writing a recursive
>routine to delete the files in the directory tree one-by-one. Thanks
this function will wipe out a directories and all files and it's subdirectories under it...
function deleteDir($dir) {
if (substr($dir, strlen($dir)-1, 1) != '/')
$dir .= '/';
if ($handle = opendir($dir))
{
while ($obj = readdir($handle))
{
if ($obj != '.' && $obj != '..')
{
if (is_dir($dir.$obj))
{
if (!deleteDir($dir.$obj))
return false;
}
elseif (is_file($dir.$obj))
{
if (!unlink($dir.$obj))
return false;
}
}
}
closedir($handle);
if (!@rmdir($dir))
return false;
return true;
}
return false;
}
how to use
$someDir = "./user/xyz/";
deleteDir($someDir);
what I usually do, is provide a popup to give the user a one last chance to change his mind before
wipping out a folder(s)/directories.
in a form
<input type="submit" name="Submit" value="Delete" onClick="return confirm('Are you sure you want to
delete this user?')" /> <br>
link
<a href="delete_user.php?del=<?= $data['userID'] ?>" onClick="return confirm('Are you sure you want
to delete this account?')">
Navigation:
[Reply to this message]
|