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

Skip to content

Commit b260ea6

Browse files
committed
[HttpFoundation] Fixed BinaryFileResponse sending wrong Content-Length header for files modified by stream wrappers/filters.
1 parent 6de4359 commit b260ea6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ public function setContentDisposition($disposition, $filename = '', $filenameFal
186186
*/
187187
public function prepare(Request $request)
188188
{
189-
$this->headers->set('Content-Length', $this->file->getSize());
189+
// Get the file size from a stream rather than from disk in case it is changed later by
190+
// stream wrappers or stream filters.
191+
$file = fopen($this->file->getPathname(), 'rb');
192+
$this->headers->set('Content-Length', fstat($file)['size']);
193+
fclose($file);
190194

191195
if (!$this->headers->has('Accept-Ranges')) {
192196
// Only accept ranges on safe HTTP methods

0 commit comments

Comments
 (0)