slick101;10916805 wrote:yea. not sure somethings up?
i use this function now...it seems to work just wondering why the other code would not work(think its a little faster from what i read on the creators post)
function ftp_delAll($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_delAll($conn_id, $dst_dir.'/'.$st_file); // if so, use recursion
}else ftp_delete($conn_id, $dst_dir.'/'.$st_file); // if not, delete the file
}
sleep(1);
ob_flush() ;
}
$flag = ftp_rmdir($conn_id, $dst_dir); // delete empty directories
return $flag;
} // end of function ftp_delAll()
Even though it's been almost a year since this post... All I have to say is this..
It's about time!! Thank you very much for this!
Any readers out there looking for a function to not only delete files recursively, but, this function does NOT cause any PHP errors / notices, etc.
I have a database driven error reporting system and as you can imagine the log would build up really fast.
The problem with most ftp_rmdir "recursive" functions out there is that they still cause errors even though the user does not see them, they are really there.
Errors Like:
ftp_rmdir() [function.ftp-rmdir]: Can't remove directory: Not a directory
OR
ftp_rmdir() [function.ftp-rmdir]: Can't remove directory: Directory not empty
Anyway, I can finally go to bad after working on this for about 3 - 4 hours now.
Thanks Again,
Luke