-
Notifications
You must be signed in to change notification settings - Fork 1
ServerRequest: getUploadedFiles Example
Terry L edited this page Jun 20, 2020
·
4 revisions
Shieldon\Psr7\ServerRequest
Extends Request.
Retrieving normalized file upload data, this method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.
-
return
array
Example:
$_FILES['avatar'] = [
'tmp_name' => '/tmp/phpmFLrzD',
'name' => 'my-avatar.png',
'type' => 'image/png',
'error' => 0,
'size' => 90996,
];
$serverRequest = new \Shieldon\Psr7\ServerRequest(
'GET',
'',
'',
[],
'1.1',
[],
[],
[],
[],
$_FILES
);
$uploadedFileArr = $serverRequests->getUploadedFiles();
echo $uploadedFileArr['avatar']->getClientFilename();
// Outputs: my-avatar.png
echo $uploadFileArr['avatar']->getClientMediaType();
// Outputs: image/png
composer require shieldon/psr-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.