system/HTTP/Files/UploadedFile.php
public function move(string $targetPath, string $name = null, bool $overwrite = false)
	{
		$targetPath = $this->setPath($targetPath); //set the target path

		if ($this->hasMoved)
		{
			throw HTTPException::forAlreadyMoved();
		}

		if (! $this->isValid())
		{
			throw HTTPException::forInvalidFile();
		}

		$targetPath  = rtrim($targetPath, '/') . '/';
		$name        = is_null($name) ? $this->getName() : $name;
		$destination = $overwrite ? $targetPath . $name : $this->getDestination($targetPath . $name);

		try
		{
			move_uploaded_file($this->path, $destination);
		}
		catch (Exception $e)
		{
			$error = error_get_last();
			throw HTTPException::forMoveFailed(basename($this->path), $targetPath, strip_tags($error['message']));
		}

		@chmod($targetPath, 0777 & ~umask());

		// Success, so store our new information
		$this->path     = $targetPath;
		$this->name     = basename($destination);
		$this->hasMoved = true;

		return true;
	}
public function move(string $targetPath, string $name = null, bool $overwrite = false)
	{
		$targetPath = $this->setPath($targetPath); //set the target path

		if ($this->hasMoved)
		{
			throw HTTPException::forAlreadyMoved();
		}

		if (! $this->isValid())
		{
			throw HTTPException::forInvalidFile();
		}

		$targetPath  = rtrim($targetPath, '/') . '/';
		$name        = is_null($name) ? $this->getName() : $name;
		$destination = $overwrite ? $targetPath . $name : $this->getDestination($targetPath . $name);

		try
		{
			move_uploaded_file($this->path, $destination);
		}
		catch (Exception $e)
		{
			$error = error_get_last();
			throw HTTPException::forMoveFailed(basename($this->path), $targetPath, strip_tags($error['message']));
		}

		@chmod($targetPath, 0777 & ~umask());

		// Success, so store our new information
		$this->path     = $targetPath;
		$this->name     = basename($destination);
		$this->hasMoved = true;

		return true;
	}
Move the uploaded file to a new location.

$targetPath may be an absolute path, or a relative path. If it is a
relative path, resolution should be the same as used by PHP's rename()
function.

The original file MUST be removed on completion.

If this method is called more than once, any subsequent calls MUST raise
an exception.

When used in an SAPI environment where $_FILES is populated, when writing
files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be
used to ensure permissions and upload status are verified correctly.

If you wish to move to a stream, use getStream(), as SAPI operations
cannot guarantee writing to stream destinations.

@see http://php.net/is_uploaded_file
@see http://php.net/move_uploaded_file

@param string  $targetPath Path to which to move the uploaded file.
@param string  $name       the name to rename the file to.
@param boolean $overwrite  State for indicating whether to overwrite the previously generated file with the same
name or not.

@return boolean

@throws \InvalidArgumentException if the $path specified is invalid.
@throws \RuntimeException on any error during the move operation.
@throws \RuntimeException on the second or subsequent call to the method.