note 46331 deleted from function.ftp-rmdir by aidan
| From: | aidan@php.net | Date: | Fri, 29 Jul 2005 07:08:34 +0000 |
| Subject: | note 46331 deleted from function.ftp-rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92692@lists.php.net to get a copy of this message | ||
Note Submitter: Sommerkorn at twt dot de
----
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
}
?>