Closed
Description
Symfony version(s) affected: 3.4.14
Description
I'm using the HttpFoundation component to stream binary files. I'm using the basic snipped underneath which produces no output. The reason for this is this line.
stream_copy_to_stream
has the following signature:
int stream_copy_to_stream(resource $source, resource $dest[, int $maxlength = -1[, int $offset = 0]])
The maxlen
and offset
properties are only actually ever set in the prepare
method. Thus Symfony passes null
to both of these parameters unless prepared
is called. PHP will not do anything if these properties are null:
How to reproduce
$response = new BinaryFileResponse($filepath);
$response->send();
Possible Solution
The solution is to call prepare
on the response. The docs do mention the prepare
method but don't say that it's mandatory.
$response = new BinaryFileResponse($filepath);
$response->prepare(Request::createFromGlobals());
$response->send();
Symfony should either:
- Be clearer in the documentation that
prepare
is necessary - Throw an error when
maxlength
oroffset
are null - Default to
-1
and0
as the default values