8000 [WebProfilerBundle] Display uploaded files in the profiler · nowiko/symfony@3f6f75b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f6f75b

Browse files
javiereguiluzfabpot
authored andcommitted
[WebProfilerBundle] Display uploaded files in the profiler
1 parent c442929 commit 3f6f75b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,33 @@
131131
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest, maxDepth: 1 }, with_context = false) }}
132132
{% endif %}
133133

134+
<h3>Uploaded files</h3>
135+
136+
{% if collector.requestfiles is empty %}
137+
<div class="empty">
138+
<p>No files were uploaded</p>
139+
</div>
140+
{% else %}
141+
<table>
142+
<thead>
143+
<tr>
144+
<th scope="col">File Name</th>
145+
<th scope="col">MIME Type</th>
146+
<th scope="col text-right">Size (bytes)</th>
147+
</tr>
148+
</thead>
149+
<tbody>
150+
{% for file in collector.requestfiles %}
151+
<tr>
152+
<td>{{ file.name }}</td>
153+
<td>{{ file.mimetype }}</td>
154+
<td class="text-right">{{ file.size|number_format }}</td>
155+
</tr>
156+
{% endfor %}
157+
</tbody>
158+
</table>
159+
{% endif %}
160+
134161
<h3>Request Attributes</h3>
135162

136163
{% if collector.requestattributes.all is empty %}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function collect(Request $request, Response $response, \Exception $except
5757
$content = false;
5858
}
5959

60+
$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+
);
68+
}
69+
}
70+
6071
$sessionMetadata = array();
6172
$sessionAttributes = array();
6273
$session = null;
@@ -95,6 +106,7 @@ public function collect(Request $request, Response $response, \Exception $except
95106
'status_code' => $statusCode,
96107
'request_query' => $request->query->all(),
97108
'request_request' => $request->request->all(),
109+
'request_files' => $requestFiles,
98110
'request_headers' => $request->headers->all(),
99111
'request_server' => $request->server->all(),
100112
'request_cookies' => $request->cookies->all(),
@@ -195,6 +207,11 @@ public function getRequestQuery()
195207
return new ParameterBag($this->data['request_query']->getValue());
196208
}
197209

210+
public function getRequestFiles()
211+
{
212+
return $this->data['request_files']->getValue(true);
213+
}
214+
198215
public function getRequestHeaders()
199216
{
200217
return new ParameterBag($this->data['request_headers']->getValue());

0 commit comments

Comments
 (0)
0