4 * @see https://github.com/laminas/laminas-diactoros for the canonical source repository
5 * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
6 * @license https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
9 declare(strict_types=1);
11 namespace Laminas\Diactoros;
14 * Create an uploaded file instance from an array of values.
16 * @param array $spec A single $_FILES entry.
17 * @throws Exception\InvalidArgumentException if one or more of the tmp_name,
18 * size, or error keys are missing from $spec.
20 function createUploadedFile(array $spec) : UploadedFile
22 if (! isset($spec['tmp_name'])
23 || ! isset($spec['size'])
24 || ! isset($spec['error'])
26 throw new Exception\InvalidArgumentException(sprintf(
27 '$spec provided to %s MUST contain each of the keys "tmp_name",'
28 . ' "size", and "error"; one or more were missing',
33 return new UploadedFile(
37 $spec['name'] ?? null,