Back to Stream class

Method move

public mixed
move
(mixed $src, mixed $dest, mixed $context = null, mixed $usePrefix = true, mixed $relative = false)
Moves a file
Parameters
  • string $src The file path to move from.
  • string $dest The file path to move to.
  • resource $context A valid context resource (optional) created with stream_context_create.
  • bool $usePrefix Controls the use of a prefix (optional).
  • bool $relative Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.
Returns
  • mixed
Since
  • 1.7.0
Class: Stream
Project: Joomla

Method move - Source code

/**
 * Moves a file
 *
 * @param   string    $src        The file path to move from.
 * @param   string    $dest       The file path to move to.
 * @param   resource  $context    A valid context resource (optional) created with stream_context_create.
 * @param   boolean   $usePrefix  Controls the use of a prefix (optional).
 * @param   boolean   $relative   Determines if the filename given is relative. Relative paths do not have JPATH_ROOT stripped.
 *
 * @return  mixed
 *
 * @since   1.7.0
 */
public function move($src, $dest, $context = null, $usePrefix = true, $relative = false)
{
    // Capture PHP errors
    $php_errormsg = '';
    $track_errors = ini_get('track_errors');
    ini_set('track_errors', true);
    $src = $this->_getFilename($src, 'w', $usePrefix, $relative);
    $dest = $this->_getFilename($dest, 'w', $usePrefix, $relative);
    if ($context) {
        // Use the provided context
        $res = @rename($src, $dest, $context);
    } elseif ($this->context) {
        // Use the object's context
        $res = @rename($src, $dest, $this->context);
    } else {
        // Don't use any context
        $res = @rename($src, $dest);
    }
    if (!$res && $php_errormsg) {
        $this->setError($php_errormsg());
    }
    $this->chmod($dest);
    // Restore error tracking to what it was before
    ini_set('track_errors', $track_errors);
    return $res;
}