Difference between revisions of "JFolder/delete"
From Joomla! Documentation
< API16:JFolder
(New page: ===Description===
Delete a folder.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{D...) |
m (removing red link to edit, no existant pages) |
||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 111: | Line 111: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 126: | Line 126: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API16]] |
Revision as of 21:52, 13 May 2013
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Delete a folder.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
delete($path)
Parameter Name | Default Value | Description |
---|---|---|
$path | The path to the folder to delete. |
Returns[edit]
boolean True on success.
Defined in[edit]
libraries/joomla/filesystem/folder.php
Importing[edit]
jimport( 'joomla.filesystem.folder' );
Source Body[edit]
function delete($path)
{
// Sanity check
if (!$path) {
// Bad programmer! Bad Bad programmer!
JError::raiseWarning(500, 'JFolder::delete: ' . JText::_('ATTEMPT_TO_DELETE_BASE_DIRECTORY'));
return false;
}
// Initialise variables.
jimport('joomla.client.helper');
$FTPOptions = JClientHelper::getCredentials('ftp');
// Check to make sure the path valid and clean
$path = JPath::clean($path);
// Is this really a folder?
if (!is_dir($path)) {
JError::raiseWarning(21, 'JFolder::delete: ' . JText::_('PATH_IS_NOT_A_FOLDER'), 'Path: ' . $path);
return false;
}
// Remove all the files in folder if they exist; disable all filtering
$files = JFolder::files($path, '.', false, true, array(), array());
if (!empty($files)) {
jimport('joomla.filesystem.file');
if (JFile::delete($files) !== true) {
// JFile::delete throws an error
return false;
}
}
// Remove sub-folders of folder; disable all filtering
$folders = JFolder::folders($path, '.', false, true, array(), array());
foreach ($folders as $folder) {
if (is_link($folder)) {
// Don't descend into linked directories, just delete the link.
jimport('joomla.filesystem.file');
if (JFile::delete($folder) !== true) {
// JFile::delete throws an error
return false;
}
} elseif (JFolder::delete($folder) !== true) {
// JFolder::delete throws an error
return false;
}
}
if ($FTPOptions['enabled'] == 1) {
// Connect the FTP client
jimport('joomla.client.ftp');
$ftp = &JFTP::getInstance(
$FTPOptions['host'], $FTPOptions['port'], null,
$FTPOptions['user'], $FTPOptions['pass']
);
}
// In case of restricted permissions we zap it one way or the other
// as long as the owner is either the webserver or the ftp
if (@rmdir($path)) {
$ret = true;
} elseif ($FTPOptions['enabled'] == 1) {
// Translate path and delete
$path = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $path), '/');
// FTP connector throws an error
$ret = $ftp->delete($path);
} else {
JError::raiseWarning(
'SOME_ERROR_CODE',
'JFolder::delete: ' . JText::_('COULD_NOT_DELETE_FOLDER'),
'Path: ' . $path
);
$ret = false;
}
return $ret;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />