Download is not working (downloads a file called download (without any extension))
MagePsycho opened this issue · 0 comments
MagePsycho commented
I have this code in Symfony for downloading the files as a zip:
<?php
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\StreamedResponse;
use ZipStream\ZipStream;
# This class doesn't exist at all (latest version)
#use ZipStream\Option\Archive;
class FileController extends AbstractController
{
public function download()
{
$zipName = 'dummy.zip';
return new StreamedResponse(function () use ($zipName) {
// Class doesn't exist at all
/*$options = new Archive();
$options->setContentType('application/octet-stream');
$options->setZeroHeader(true);
$options->setFlushOutput(true);
$options->setSendHttpHeaders(true);*/
$zip = new ZipStream($zipName);
$zip->addFile('hello.txt', 'this is message for hello.txt');
$zip->finish();
});
}
}
But when I try to download, it always dumps download
file without any extension.
FYI, I using Symfony 6.2, PHP 8.1 and ZipStream 3.0