You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've few .pdf links to include to a .zip archive.
The .pdf links are direct download links, so the code I found here doesn't work.
The .zip archive is generated, but with empty files in here
Example code
$response = newStreamedResponse(function () use ($invoicesLines) {
$options = newArchive();
$options->setContentType('application/octet-stream');
// this is needed to prevent issues with truncated zip files$options->setZeroHeader(true);
//initialise zipstream with output zip filename and options.$zip = newZipStream('invoices.zip', $options);
foreach ($invoicesLinesas$invoice) {
$fp = tmpfile();
// Download File$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_URL, $invoice->getLink());
curl_exec($ch);
// Force to write all datafflush($fp);
// Rewind to the beginning, otherwise the stream is at the end from the startrewind($fp);
// Add File$zip->addFileFromStream(sprintf('%s.pdf', $invoice->getNumber()), $fp);
// Close the Temp Filefclose($fp);
}
$zip->finish();
});
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
$response->headers->set('Content-Disposition', sprintf('attachment;filename="%s"', 'invoices.zip'));
$response->headers->set('Cache-Control', 'max-age=0');
return$response;
This discussion was converted from issue #204 on January 28, 2022 11:10.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Description of the problem
I've few .pdf links to include to a .zip archive.
The .pdf links are direct download links, so the code I found here doesn't work.
The .zip archive is generated, but with empty files in here
Example code
Informations
Beta Was this translation helpful? Give feedback.
All reactions