Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3778585

Browse files
bug #29183 [HttpKernel] Fix collecting uploaded files (ro0NL)
This PR was squashed before being merged into the 4.2-dev branch (closes #29183). Discussion ---------- [HttpKernel] Fix collecting uploaded files | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #29178 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Commits ------- a439681 [HttpKernel] Fix collecting uploaded files
2 parents 6eb5f93 + a439681 commit 3778585

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<tr>
144144
<th scope="col">File Name</th>
145145
<th scope="col">MIME Type</th>
146-
<th scope="col text-right">Size (bytes)</th>
146+
<th scope="col" class="text-right">Size (bytes)</th>
147147
</tr>
148148
</thead>
149149
<tbody>

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\HttpFoundation\Cookie;
16+
use Symfony\Component\HttpFoundation\File\UploadedFile;
1617
use Symfony\Component\HttpFoundation\ParameterBag;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpFoundation\Response;
@@ -58,15 +59,20 @@ public function collect(Request $request, Response $response, \Exception $except
5859
}
5960

6061
$requestFiles = array();
61-
foreach ($request->files->all() as $files) {
62-
foreach ($files as $fileName => $fileData) {
63-
$requestFiles[] = array(
64-
'name' => $fileData->getClientOriginalName(),
65-
'mimetype' => $fileData->getMimeType(),
66-
'size' => $fileData->getSize(),
67-
);
62+
$extractFiles = function (array $files) use (&$extractFiles, &$requestFiles) {
63+
foreach ($files as $file) {
64+
if ($file instanceof UploadedFile) {
65+
$requestFiles[] = array(
66+
'name' => $file->getClientOriginalName(),
67+
'mimetype' => $file->getMimeType(),
68+
'size' => $file->getSize(),
69+
);
70+
} elseif (\is_array($file)) {
71+
$extractFiles($file);
72+
}
6873
}
69-
}
74+
};
75+
$extractFiles($request->files->all());
7076

7177
$sessionMetadata = array();
7278
$sessionAttributes = array();

0 commit comments

Comments
 (0)