Actions

API16

Difference between revisions of "JFile/move"

From Joomla! Documentation

< API16:JFile
(New page: ===Description=== Moves a file <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> {{Descripti...)
 
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>[[Description:JFile/move|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JFile/move}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 95: Line 95:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JFile/move|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JFile/move}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 110: Line 110:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 00:07, 13 May 2013

Replacement filing cabinet.png
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

Moves a file

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

move($src, $dest, $path= '', $use_streams=false)
Parameter Name Default Value Description
$src $src The path to the source file
$dest $dest The path to the destination file
$path $path An optional base path to prefix to the file names
$use_streams false

Returns

boolean True on success

Defined in

libraries/joomla/filesystem/file.php

Importing

jimport( 'joomla.filesystem.file' );

Source Body

function move($src, $dest, $path = '', $use_streams=false)
{
 
        if ($path) {
                $src = JPath::clean($path.DS.$src);
                $dest = JPath::clean($path.DS.$dest);
        }
 
        //Check src path
        if (!is_readable($src)) { // && !is_writable($src)) { // file may not be writable by php if via ftp!
                return JText::_('CANNOT_FIND_SOURCE_FILE');
        }
 
        if($use_streams) {
                $stream =& JFactory::getStream();
                if(!$stream->move($src, $dest)) {
                        JError::raiseWarning(21, 'JFile::move: '. $stream->getError());
                        return false;
                }
                return true;
        } else {
                // Initialise variables.
                jimport('joomla.client.helper');
                $FTPOptions = JClientHelper::getCredentials('ftp');
 
        if ($FTPOptions['enabled'] == 1) {
                // Connect the FTP client
                jimport('joomla.client.ftp');
                $ftp = & JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
 
                //Translate path for the FTP account
                $src    = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $src), '/');
                $dest   = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
 
                // Use FTP rename to simulate move
                if (!$ftp->rename($src, $dest)) {
                        JError::raiseWarning(21, JText::_('Rename failed'));
                        return false;
                }
        } else {
                if (!@ rename($src, $dest)) {
                        JError::raiseWarning(21, JText::_('Rename failed'));
                        return false;
                }
        }
        return true;
}
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />