[horde] FTP VFS Recursive Delete Function
Jeff Graves
jeff at image-src.com
Tue Mar 25 06:56:32 PST 2003
I'm not sure the diff worked so I'm attaching the relevant methods
from my horde/lib/VFS/ftp.php file as well.
Jeff Graves
Customer Support Engineer
Image Source, Inc.
10 Mill Street
Bellingham, MA 02019
jeff at image-src.com - Email
508.966.5200 X31 - Phone
508.966.5170 - Fax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftp.php.diff
Type: application/octet-stream
Size: 2442 bytes
Desc: not available
Url : http://lists.horde.org/archives/horde/attachments/20030325/0615979d/ftp.php-0002.obj
-------------- next part --------------
/**
* Delete a folder from the VFS.
*
* @param string $path The path to delete the folder from.
* @param string $name The name of the folder to delete.
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function deleteFolder($path, $name)
{
$result = $this->recursiveDelete($path, $name);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
return true;
}
/**
* Recursively deletes a folder from the VFS.
*
* @param string $path The path to delete the folder from.
* @param string $name The name of the folder to delete.
*
* @return mixed True on success or a PEAR_Error object on failure.
*/
function recursiveDelete($path, $name)
{
$conn = $this->_connect();
if (is_a($conn, 'PEAR_Error')) {
return $conn;
}
$isDir = false;
$dirCheck = $this->listFolder($path);
foreach ($dirCheck as $file) {
if ($file['name'] == $name && $file['type'] == '**dir') {
$isDir = true;
break;
}
}
if ($isDir) {
$file_list = $this->listFolder($this->_getPath($path, $name));
if (is_a($file_list, 'PEAR_Error')) {
return $file_list;
}
foreach ($file_list as $file) {
if ($file['type'] == '**dir') {
$result = $this->recursiveDelete($this->_getPath($path, $name), $file['name']);
if(is_a($result, 'PEAR_Error')) {
return $result;
}
} else {
$result = $this->deleteFile($this->_getPath($path, $name), $file['name']);
if(is_a($result, 'PEAR_Error')) {
return $result;
}
}
}
if(!(@ftp_rmdir($this->_stream, $this->_getPath($path, $name)))) {
return PEAR::raiseError('Cannot remove directory: ' . $this->_getPath($path, $name));
}
} else {
if(!(@ftp_delete($this->_stream, $this->_getPath($path, $name)))) {
return PEAR::raiseError('Cannot delete file: '. $this->_getPath($path, $name));
}
}
return true;
}
More information about the horde
mailing list