Closed
Description
Description
In some application developers no want to create new file in file system and can use SplTempFileObject for write to filesystem and next return as attachment for download.
But now BinaryFileResponse
support only SplFileInfo
, SplFileObject
and get path of file, but SplTempFileObject
returns php://temp
as path (as result we receive error - The file "php://temp" does not exist
).
Example
$file = new \SplTempFileObject();
$file->fputcsv(['Shop', 'Client', 'Card', 'Total', 'Pending', 'Success', 'Declined']);
foreach ($groupedPans as $groupedPan) {
foreach ($groupedPan->cards as $card) {
$file->fputcsv([
$groupedPan->customer->getShop()->getName(),
$groupedPan->customer->getClientId(),
$card->pan,
$card->total,
$card->pending,
$card->success,
$card->declined
]);
}
}
$response = new BinaryFileResponse($file);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'banks.csv');
return $response;