Wrong download file name #248
Answered
by
maennchen
MagePsycho
asked this question in
Q&A
-
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 FYI, I using Symfony 6.2, PHP 8.1 and ZipStream 3.0 |
Beta Was this translation helpful? Give feedback.
Answered by
maennchen
Mar 8, 2023
Replies: 1 comment
-
@MagePsycho You’ll have to set the correct filename using the outputName named argument. With the code above, not the name but the comment is set. See https://maennchen.dev/ZipStream-PHP/classes/ZipStream-ZipStream.html#method___construct |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
maennchen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MagePsycho You’ll have to set the correct filename using the outputName named argument. With the code above, not the name but the comment is set.
See https://maennchen.dev/ZipStream-PHP/classes/ZipStream-ZipStream.html#method___construct