Actions

API16

JFolder/move

From Joomla! Documentation

< API16:JFolder
Revision as of 17:47, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 folder.

[Edit Descripton]

Description:JFolder/move

Syntax

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

Returns

mixed Error message on false or boolean true on success.

Defined in

libraries/joomla/filesystem/folder.php

Importing

jimport( 'joomla.filesystem.folder' );

Source Body

function move($src, $dest, $path = '', $use_streams=false)
{
        // Initialise variables.
        jimport('joomla.client.helper');
        $FTPOptions = JClientHelper::getCredentials('ftp');
 
        if ($path) {
                $src = JPath::clean($path . DS . $src);
                $dest = JPath::clean($path . DS . $dest);
        }
 
        if (!JFolder::exists($src)) {
                return JText::_('Cannot find source folder');
        }
        if (JFolder::exists($dest)) {
                return JText::_('Folder already exists');
        }
        if($use_streams) {
                $stream =& JFactory::getStream();
                if(!$stream->move($src, $dest)) {
                        return JText::_('Rename failed').': '. $stream->getError();
                        //return JError::raiseError(-1, JText::_('Rename failed').': '. $stream->getError()));
                }
                $ret = true;
        } else {
        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)) {
                        return JText::_('Rename failed');
                }
                $ret = true;
        } else {
                if (!@rename($src, $dest)) {
                        return JText::_('Rename failed');
                }
                $ret = true;
        }
        }
        return $ret;
}

[Edit See Also] SeeAlso:JFolder/move

Examples

<CodeExamplesForm />