note 98676 deleted from function.ftp-rmdir by visualmind

From: Date: Wed, 30 Jun 2010 10:31:56 +0000
Subject: note 98676 deleted from function.ftp-rmdir by visualmind
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170581@lists.php.net to get a copy of this message
Note Submitter: ittgung ---- 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,"");

« previous php.notes (#170581) next »