API15:JFile/delete
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Delete a file or array of files
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
delete($file)
| Parameter Name | Default Value | Description |
|---|---|---|
| $file | $file The file name or an array of file names |
Returns
boolean True on success
Defined in
libraries/joomla/filesystem/file.php
Importing
jimport( 'joomla.filesystem.file' );
Source Body
function delete($file) { // Initialize variables jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); if (is_array($file)) { $files = $file; } else { $files[] = $file; } // Do NOT use ftp if it is not enabled if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = & JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); } foreach ($files as $file) { $file = JPath::clean($file); // Try making the file writeable first. If it's read-only, it can't be deleted // on Windows, even if the parent folder is writeable @chmod($file, 0777); // 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 (@unlink($file)) { // Do nothing } elseif ($FTPOptions['enabled'] == 1) { $file = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $file), '/'); if (!$ftp->delete($file)) { // FTP connector throws an error return false; } } else { $filename = basename($file); JError::raiseWarning('SOME_ERROR_CODE', JText::_('Delete failed') . ": '$filename'"); return false; } } return true; }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
