public function move(string $targetDirectory, string $name = null)
    {
        if ($this->hasErrors()) {
            throw new UploadException('Cannot move file with errors');
        }

        if (!is_dir($targetDirectory)) {
            if (!mkdir($targetDirectory, 0777, true)) {
                throw new UploadException('Could not create directory ' . $targetDirectory);
            }
        } elseif (!is_writable($targetDirectory)) {
            throw new UploadException($targetDirectory . ' is not writable');
        }

        $name = $name ?: $this->getBasename();
        $targetPath = rtrim($targetDirectory, '\\/') . '/' . $name;

        if (!$this->doMove($this->getPathname(), $targetPath)) {
            throw new UploadException('Could not move the uploaded file');
        }
    }
public function move(string $targetDirectory, string $name = null)
    {
        if ($this->hasErrors()) {
            throw new UploadException('Cannot move file with errors');
        }

        if (!is_dir($targetDirectory)) {
            if (!mkdir($targetDirectory, 0777, true)) {
                throw new UploadException('Could not create directory ' . $targetDirectory);
            }
        } elseif (!is_writable($targetDirectory)) {
            throw new UploadException($targetDirectory . ' is not writable');
        }

        $name = $name ?: $this->getBasename();
        $targetPath = rtrim($targetDirectory, '\\/') . '/' . $name;

        if (!$this->doMove($this->getPathname(), $targetPath)) {
            throw new UploadException('Could not move the uploaded file');
        }
    }
public function move ( string $ targetDirectory , string $ name = null ) { if ( $ this -> hasErrors ( ) ) { throw new UploadException ( 'Cannot move file with errors' ) ; } if ( ! is_dir ( $ targetDirectory ) ) { if ( ! mkdir ( $ targetDirectory , 0777 , true ) ) { throw new UploadException ( 'Could not create directory ' . $ targetDirectory ) ; } } elseif ( ! is_writable ( $ targetDirectory ) ) { throw new UploadException ( $ targetDirectory . ' is not writable' ) ; } $ name = $ name ? : $ this -> getBasename ( ) ; $ targetPath = rtrim ( $ targetDirectory , '\\/' ) . '/' . $ name ; if ( ! $ this -> doMove ( $ this -> getPathname ( ) , $ targetPath ) ) { throw new UploadException ( 'Could not move the uploaded file' ) ; } }
Moves the file to the target path

@param string $targetDirectory The target directory
@param string|null $name The new name
@throws UploadException Thrown if the file could not be moved
Moves the file to the target path