View Full Version : Delete Directorty
DsgnrsTLZAdmin
12-14-2004, 11:39 PM
How do I delete a directory that is not empty? If not possible, how do I delete all the file in a directory?
How do I delete a directory that is not empty? If not possible, how do I delete all the file in a directory?
if your server is running Linux:shell_exec('rm -rf /path/to/dir/');
or you could use php's functions to do it, but you would probably have to write a recursive function... the above is faster though so try that.
DsgnrsTLZAdmin
12-15-2004, 01:41 AM
Thank you. That works out. Look like a major potential security problem however.
Thank you. That works out. Look like a major potential security problem however.
yeah. you can do escapeshellarg, http://www.php.net/escapeshellarg
shell_exec('rm -rf '.escapeshellarg($path));
I probably should've mentioned that in my previous.. sorry about that.
Horus Kol
12-15-2004, 08:56 AM
I wrote this recursive function to strip all the contents from a given directory:
function file_RemoveDir($dir)
{
$current_dir = opendir($dir);
while ($f = readdir($current_dir))
{
if ((is_dir("$dir/$f"))&&($f != ".")&&($f != ".."))
file_RemoveDir($dir);
elseif (($f != ".")&&($f != ".."))
unlink("$dir/$f");
}
closedir($current_dir);
rmdir($dir);
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.