note 79844 added to function.ftp-rmdir

From: Date: Fri, 14 Dec 2007 22:04:59 +0000
Subject: note 79844 added to function.ftp-rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-133485@lists.php.net to get a copy of this message
I got tired of trying other people's implementations of recursive FTP deletion, so I wrote my own. It's full of helpful comments and straightforward PHP. Enjoy! (I'm running PHP 4.7 I believe) Returns false on error, true on success. /** * Recursively delete a directory. * * @param string $resource FTP connection resource * @param string $path Path to the directory on the FTP-server relative to the current working directory */ function delete_dir_recursive($resource, $path) { $list = ftp_nlist($resource, $path); foreach($list as $item) { //Skip . and .. if($item=='.' || $item=='..') continue; //Delete files elseif($item==$path) { if(ftp_delete($resource, $path)===FALSE) return FALSE; } //Recursively enter directories else { //If there were any errors in the recursive call execution, return immediately. if(!delete_dir_recursive($resource, "$path/$item")) return FALSE; //If the directory is not yet empty, continue deleting entries. if(sizeof(ftp_nlist($resource, $path))>2) continue; //Delete directories after we've deleted all files within them (*after* the recursive call) if(ftp_rmdir($resource, $path)===FALSE) return FALSE; } } return TRUE; } ---- Server IP: 69.147.83.197 Probable Submitter: 72.8.99.12 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-rmdir.php Edit -- https://master.php.net/note/edit/79844 Del: integrated -- https://master.php.net/note/delete/79844/integrated Del: useless -- https://master.php.net/note/delete/79844/useless Del: bad code -- https://master.php.net/note/delete/79844/bad+code Del: spam -- https://master.php.net/note/delete/79844/spam Del: non-english -- https://master.php.net/note/delete/79844/non-english Del: in docs -- https://master.php.net/note/delete/79844/in+docs Del: other reasons-- https://master.php.net/note/delete/79844 Reject -- https://master.php.net/note/reject/79844 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133485) next »