-
Notifications
You must be signed in to change notification settings - Fork 1
UploadedFileFactory: createUploadedFile Example
Terry L edited this page Jun 21, 2020
·
4 revisions
Shieldon\Psr17\UploadedFileFactory
Create a new uploaded file. If a size is not provided it will be determined by checking the size of the stream.
-
param
StreamInterfacestream*The underlying stream representing the uploaded file content. -
param
int|nullsize= nullThe size of the file in bytes. -
param
interror= 0The PHP file upload error. -
param
string|nullclientFilename= nullThe filename as provided by the client, if any. -
param
string|nullclientMediaType= nullThe media type as provided by the client, if any. -
return
UploadedFileInterface
Example:
$uploadedFileFactory = new UploadedFileFactory();
$sourcePath = BOOTSTRAP_DIR . '/sample/shieldon_logo.png';
$targetPath = STORAGE_DIR . '/images/shieldon_logo.png';
$streamFactory = new StreamFactory();
$uploadedFileFactory = new UploadedFileFactory();
$stream = $streamFactory->createStreamFromFile($sourcePath);
$uploadedFile = $uploadedFileFactory->createUploadedFile($stream);
// Move file from $sourcePath to $targetPath.
$uploadedFile->moveTo($targetPath);composer require shieldon/psr-httpShieldon PSR HTTP implementation written by Terry L. from Taiwan.
