Skip to content

UploadedFile: moveTo Example

Terry L edited this page Jun 20, 2020 · 2 revisions

Shieldon\Psr7\UploadedFile

moveTo($targetPath)

Move the uploaded file to a new location.

  • param string targetPath * Path to which to move the uploaded file.
$stream = new Stream(
    fopen(BOOTSTRAP_DIR . '/sample/shieldon_logo.png', 'r+')
);

$uploadedFile = new UploadedFile($stream);

$uploadedFile->moveTo('/home/terrylin/public/image_cache/shieldon_logo_png');

if (
    file_exists('/home/terrylin/public/image_cache/shieldon_logo_png') &&
    ! file_exists(BOOTSTRAP_DIR . '/sample/shieldon_logo.png')
) {
    echo 'File has been moved to the new place.';
} else {
    echo 'Cannot move file.';
}
// Outputs: File has been moved to the new place.
Clone this wiki locally