Three file inputs, last being "multiple". Let's say we upload a file on each, and three on the multiple input (upload3
).
<input type="file" name="upload1">
<input type="file" name="upload2">
<input type="file" name="upload3[]" multiple> <!-- note the [] on name to indicate array -->
Getting files off Request:
/** @var Symfony\Component\HttpFoundation\Request $request */
$request->files; // Symfony\Component\HttpFoundation\FileBag
FileBag
is iterable. Iterated, looks like:
[
'upload1' => Symfony\Component\HttpFoundation\File\UploadedFile,
'upload2' => Symfony\Component\HttpFoundation\File\UploadedFile,
'upload3' => [
Symfony\Component\HttpFoundation\File\UploadedFile,
Symfony\Component\HttpFoundation\File\UploadedFile,
Symfony\Component\HttpFoundation\File\UploadedFile,
]
]
Getting info from an UploadedFile
:
print_r([
'getClientOriginalName' => $file->getClientOriginalName(),
'getFilename' => $file->getFilename(),
'getClientOriginalExtension' => $file->getClientOriginalExtension(),
'getExtension' => $file->getExtension(),
'guessExtension' => $file->guessExtension(),
'getClientMimeType' => $file->getClientMimeType(),
'getMimeType' => $file->getMimeType(),
'getPath' => $file->getPath(),
'getPathname' => $file->getPathname(),
'getRealPath' => $file->getRealPath(),
]);
Ran against an uploaded file named composer.json
, gives us:
Array
(
[getClientOriginalName] => composer.json
[getFilename] => phpdLcSXY
[getClientOriginalExtension] => json
[getExtension] =>
[guessExtension] => txt
[getClientMimeType] => application/json
[getMimeType] => text/plain
[getPath] => /private/var/folders/w3/5zrdfsn55w3d_lwtf7ry2wn00000gn/T
[getPathname] => /private/var/folders/w3/5zrdfsn55w3d_lwtf7ry2wn00000gn/T/phpdLcSXY
[getRealPath] => /private/var/folders/w3/5zrdfsn55w3d_lwtf7ry2wn00000gn/T/phpdLcSXY
)
Thanks a lot, you saved me ๐ ๐