Embryo/Http/Message/UploadedFile.php
public function moveTo($targetPath)
        {
            if ($this->moved) {
                throw new \RuntimeException('Uploaded file already moved');
            }

            if (!is_string($targetPath) || $targetPath === '') {
                throw new \InvalidArgumentException('Target path must be a non empty string');
            }

            $stream = $this->getStream();
            $file   = $stream->getMetadata('uri');

            if (is_dir($targetPath)) {
                
                if (!is_writable($targetPath)) {
                    throw new \InvalidArgumentException('Target path is not writable');
                }
                $target = rtrim($targetPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->clientFilename;
                
            } else {
                
                if (!is_writable(dirname($targetPath))) {
                    throw new \InvalidArgumentException('Target path is not writable');
                }
                $target = $targetPath;

            }
            
            if (!copy($file, $target)) {
                throw new \RuntimeException(sprintf('Error coping uploaded file %1s to %2s', $this->clientFilename, $targetPath));
            }
        
            $this->moved = true;
            if (!$this->moved) {
                throw new \RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath));
            }
        }
public function moveTo($targetPath)
        {
            if ($this->moved) {
                throw new \RuntimeException('Uploaded file already moved');
            }

            if (!is_string($targetPath) || $targetPath === '') {
                throw new \InvalidArgumentException('Target path must be a non empty string');
            }

            $stream = $this->getStream();
            $file   = $stream->getMetadata('uri');

            if (is_dir($targetPath)) {
                
                if (!is_writable($targetPath)) {
                    throw new \InvalidArgumentException('Target path is not writable');
                }
                $target = rtrim($targetPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->clientFilename;
                
            } else {
                
                if (!is_writable(dirname($targetPath))) {
                    throw new \InvalidArgumentException('Target path is not writable');
                }
                $target = $targetPath;

            }
            
            if (!copy($file, $target)) {
                throw new \RuntimeException(sprintf('Error coping uploaded file %1s to %2s', $this->clientFilename, $targetPath));
            }
        
            $this->moved = true;
            if (!$this->moved) {
                throw new \RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath));
            }
        }
public function moveTo ( $ targetPath ) { if ( $ this -> moved ) { throw new \ RuntimeException ( 'Uploaded file already moved' ) ; } if ( ! is_string ( $ targetPath ) || $ targetPath === '' ) { throw new \ InvalidArgumentException ( 'Target path must be a non empty string' ) ; } $ stream = $ this -> getStream ( ) ; $ file = $ stream -> getMetadata ( 'uri' ) ; if ( is_dir ( $ targetPath ) ) { if ( ! is_writable ( $ targetPath ) ) { throw new \ InvalidArgumentException ( 'Target path is not writable' ) ; } $ target = rtrim ( $ targetPath , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ this -> clientFilename ; } else { if ( ! is_writable ( dirname ( $ targetPath ) ) ) { throw new \ InvalidArgumentException ( 'Target path is not writable' ) ; } $ target = $ targetPath ; } if ( ! copy ( $ file , $ target ) ) { throw new \ RuntimeException ( sprintf ( 'Error coping uploaded file %1s to %2s' , $ this -> clientFilename , $ targetPath ) ) ; } $ this -> moved = true ; if ( ! $ this -> moved ) { throw new \ RuntimeException ( sprintf ( 'Uploaded file could not be moved to %s' , $ targetPath ) ) ; } }
Moves the uploaded file to a new location.

@see http://php.net/is_uploaded_file
@see http://php.net/move_uploaded_file
@param string $targetPath
@throws InvalidArgumentException
@throws RuntimeException
Moves the uploaded file to a new location .