Skip to content

Instantly share code, notes, and snippets.

@samsonasik
Last active Aug 11, 2022
Embed
What would you like to do?
barcode save download
<?php
// ...
public function barcodeAction()
{
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
$barcode = \Zend\Barcode\Barcode::factory('code39', 'Image', $barcodeOptions);
//temporary save file into data folder
imagegif($barcode->draw(), './data/barcode.gif');
$response = $this->getResponse();
//setting response header....
$response->getHeaders()->addHeaderLine('Content-Type', 'image/gif');
$response->getHeaders()->addHeaderLine('Content-Disposition', 'attachment; filename="barcode.gif"');
$response->getHeaders()->addHeaderLine('Content-Length', filesize('./data/barcode.gif'));
// set response with get content of pdf
$response->setContent(file_get_contents('./data/barcode.gif'));
//remove file after no need
@unlink('./data/barcode.gif');
return $response;
}
@resourcemode
Copy link

Thank you, it works perfectly! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment