note 98676 added to function.ftp-rmdir

From: Date: Wed, 30 Jun 2010 05:00:46 +0000
Subject: note 98676 added to function.ftp-rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-170577@lists.php.net to get a copy of this message
Hi all, I have edited from former post, by adding one more parameter, "$item". It's work!! function DeleteDirRecursive($resource, $path, $item) { $result_message = ""; $list = ftp_nlist ($resource, $path); if ( empty($list) ) { $list = RawlistToNlist( ftp_rawlist($resource, $path), $path . ( substr($path, strlen($path) - 1, 1) == "/" ? "" : "/" ) ); } if ($list[0] != $item) { $path .= ( substr($path, strlen($path)-1, 1) == "/" ? "" : "/" ); foreach ($list as $item) { if ($item == ".." || $item == ".") { }else{ $result_message .= DeleteDirRecursive($resource, $path.$item, $item); } } if (ftp_rmdir ($resource, $path)) { $result_message .= "Successfully deleted dir $path <br />\n"; } else { $result_message .= "There was a problem while deleting dir $path <br />\n"; } } else { if (ftp_delete ($resource, $path)) { $result_message .= "Successfully deleted file $path <br />\n"; } else { $result_message .= "There was a problem while deleting file $path <br />\n"; } } return $result_message; } /** * Convert a result from ftp_rawlist() to a result of ftp_nlist() * * @param array $rawlist Result from ftp_rawlist(); * @param string $path Path to the directory on the FTP-server relative to the current working directory * @return array An array with the paths of the files in the directory */ function RawlistToNlist($rawlist, $path) { $array = array(); foreach ($rawlist as $item) { $filename = trim(substr($item, 55, strlen($item) - 55)); if ($filename == "." || $filename == "..") { }else{ $array[] = $path . $filename; } } return $array; } $msg=DeleteDirRecursive($conn_id,$hidPath,""); ---- Server IP: 69.147.83.197 Probable Submitter: 117.121.221.80 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-rmdir.php Edit -- https://master.php.net/note/edit/98676 Del: integrated -- https://master.php.net/note/delete/98676/integrated Del: useless -- https://master.php.net/note/delete/98676/useless Del: bad code -- https://master.php.net/note/delete/98676/bad+code Del: spam -- https://master.php.net/note/delete/98676/spam Del: non-english -- https://master.php.net/note/delete/98676/non-english Del: in docs -- https://master.php.net/note/delete/98676/in+docs Del: other reasons-- https://master.php.net/note/delete/98676 Reject -- https://master.php.net/note/reject/98676 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170577) next »