Transfers a file to the client using HTTP.
Pipes a file through Drupal to the client.
$uri: String specifying the file URI to transfer.
$headers: An array of HTTP headers to send along with file.
function file_transfer($uri, $headers) {
return new StreamedResponse(function () use ($uri) {
// Transfer file in 1024 byte chunks to save memory usage.
if (file_exists($uri) && ($fd = fopen($uri, 'rb'))) {
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($fd);
}
}, 200, $headers);
}