note 66097 deleted from function.ftp-rmdir by danbrown

From: Date: Wed, 30 Jun 2010 12:04:35 +0000
Subject: note 66097 deleted from function.ftp-rmdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170587@lists.php.net to get a copy of this message
Note Submitter: mail at martinauer dot net ---- At least in PHP 4.3.11 ftp_nlist lists complete paths, not just filenames. Therefore the function by uma at di4 dot com did not work for me. But it worked with a small change in line 6 like this: function ftp_rmAll($conn_id,$dst_dir){ $ar_files = ftp_nlist($conn_id, $dst_dir); //var_dump($ar_files); if (is_array($ar_files)){ // makes sure there are files for ($i=0;$i<sizeof($ar_files);$i++){ // for each file $st_file = basename($ar_files[$i]); if($st_file == '.' || $st_file == '..') continue; if (ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1){ // check if it is a directory ftp_rmAll($conn_id, $dst_dir.'/'.$st_file); // if so, use recursion } else { ftp_delete($conn_id, $dst_dir.'/'.$st_file); // if not, delete the file } } } $flag = ftp_rmdir($conn_id, $dst_dir); // delete empty directories //return $flag; }

« previous php.notes (#170587) next »