Skip to content

ServerRequest: getUploadedFiles Example

Terry L edited this page Jun 20, 2020 · 4 revisions
Clone this wiki locally

Shieldon\Psr7\ServerRequest

Extends Request.

getUploadedFiles()

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