Skip to content

Instantly share code, notes, and snippets.

@samsonasik
Last active August 11, 2022 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsonasik/2918538105eeedaf57a5 to your computer and use it in GitHub Desktop.
Save samsonasik/2918538105eeedaf57a5 to your computer and use it in GitHub Desktop.
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