-
Notifications
You must be signed in to change notification settings - Fork 2
PSR 17: UploadedFileFactory Example
Terry L edited this page Jun 21, 2020
·
3 revisions
Namespace
Shieldon\Psr17\UploadedFileFactory
None
-
param
StreamInterface
stream*
The underlying stream representing the uploaded file content. -
param
int|null
size= null
The size of the file in bytes. -
param
int
error= 0
The PHP file upload error. -
param
string|null
clientFilename= null
The filename as provided by the client, if any. -
param
string|null
clientMediaType= null
The 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-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.