Title: UploadedFile::moveTo
Published: May 20, 2026
Last modified: August 20, 2026

---

# UploadedFile::moveTo( $targetPath )

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/moveto/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/moveto/?output_format=md#related)

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/moveto/?output_format=md#source)󠁿

    ```php
    public function moveTo($targetPath): void
    {
        $this->validateActive();
        if (!\is_string($targetPath) || '' === $targetPath) {
            throw new \InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
        }
        if (null !== $this->file) {
            $this->moved = 'cli' === \PHP_SAPI ? @\rename($this->file, $targetPath) : @\move_uploaded_file($this->file, $targetPath);
            if (\false === $this->moved) {
                throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s": %s', $targetPath, \error_get_last()['message'] ?? ''));
            }
        } else {
            $stream = $this->getStream();
            if ($stream->isSeekable()) {
                $stream->rewind();
            }
            if (\false === $resource = @\fopen($targetPath, 'w')) {
                throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $targetPath, \error_get_last()['message'] ?? ''));
            }
            $dest = Stream::create($resource);
            while (!$stream->eof()) {
                if (!$dest->write($stream->read(1048576))) {
                    break;
                }
            }
            $this->moved = \true;
        }
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/third-party/nyholm/psr7/uploadedfile.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/UploadedFile.php#L94)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/UploadedFile.php#L94-L121)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/moveto/?output_format=md#related)󠁿

| Uses | Description | 
| [UploadedFile::validateActive()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/validateactive/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/UploadedFile.php` |  | 
| [UploadedFile::getStream()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/getstream/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/UploadedFile.php` |  | 
| [Stream::read()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-stream/read/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php` |  | 
| [Stream::isSeekable()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-stream/isseekable/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php` |  | 
| [Stream::rewind()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-stream/rewind/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php` |  | 
| [Stream::eof()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-stream/eof/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php` |  | 
| [Stream::create()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-stream/create/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php` |

Creates a new PSR-7 stream.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/moveto/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uploadedfile/moveto/?output_format=md#)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclientdependencies-nyholm-psr7-uploadedfile%2Fmoveto%2F)
before being able to contribute a note or feedback.