note 34689 deleted from function.ftp-delete by aidan
| From: | aidan@php.net | Date: | Fri, 29 Jul 2005 07:09:02 +0000 |
| Subject: | note 34689 deleted from function.ftp-delete by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92698@lists.php.net to get a copy of this message | ||
Note Submitter: lucas at rufy dot com
----
The following function will recursively delete any files in a destination directory through FTP. See
http://rufy.com/tech/archives/000026.html
for more information.
NOTE: use full path name for the destination directory
function ftp_rmAll($conn_id,$dst_dir){
$ar_files = ftp_nlist($conn_id, $dst_dir);
if (is_array($ar_files)){ // makes sure there are files
for ($i=0;$i<sizeof($ar_files);$i++){ // for each file
$st_file = $ar_files[$i];
if (ftp_size($conn_id, $st_file) == -1){ // check if it is a directory
ftp_rmAll($conn_id, $st_file); // if so, use recursion
} else {
ftp_delete($conn_id, $st_file); // if not, delete the file
}
}
}
ftp_rmdir($conn_id, $dst_dir); // delete empty directories
}