note 46331 added to function.ftp-rmdir
| From: | Sommerkorn at twt dot de | Date: | Thu, 07 Oct 2004 12:06:12 +0000 |
| Subject: | note 46331 added to function.ftp-rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78120@lists.php.net to get a copy of this message | ||
The function ftp_size seems not to work on every FTP-Server. Using ftp_rawlist in combination with
regular expressions is a slightly safer way to check for directories.
<?
function ftp_rmAll($conn_id,$dst_dir)
{
$ar_files = ftp_rawlist($conn_id, $dst_dir);
if (is_array($ar_files)) { // makes sure there are files
foreach ($ar_files as $st_file) { // for each file
if (ereg("([-d][rwxst-]+).* ([0-9]) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*)
([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)",$st_file,$regs)) {
if (substr($regs[1],0,1)=="d") { // check if it is a directory
ftp_rmAll($conn_id, $dst_dir."/".$regs[8]); // if so, use recursion
} else {
ftp_delete($conn_id, $dst_dir."/".$regs[8]); // if not, delete the file
}
}
}
}
ftp_rmdir($conn_id, $dst_dir); // delete empty directories
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.ftp-rmdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46331
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46331&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46331&report=yes
Search -- http://master.php.net/manage/user-notes.php