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

Skip to content

[BinaryFileResponse] Possible to use SplTempFileObject for download attachments. #48530

Closed
@ZhukV

Description

@ZhukV

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions