PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Images » Image_Barcode » Bug #7851

Needs flag to supress headers or an option to redirect output to a variable.

Details

Request #7851Needs flag to supress headers or an option to redirect output to a variable.
Submitted2006-06-09 19:44 UTC
Fromtdrake at tymail dot com
Assignedcweiske
StatusClosed
PackageImage_Barcode
PHP Version5.0.5
OSlinux
Roadmaps(Not assigned)

Comments

[2006-06-09 19:44 UTC] tdrake at tymail dot com

Description:
------------
This extension would be a lot more useful if the headers could be suppressed or the output could be redirected to a variable.

For example, I was attempting to embed the barcode images that were generated into a PDF document. To do this, the images must be written to files so that they can be imported with pdf_open_image_file function. Generating the image can be accomplished easily enough with the ob_get_contents command and dumping the buffer to a file. Unfortunately, when the script runs, the barcode app sends a header that the document is a graphic, when in fact the document is a PDF. The browser then proceeds to throw an error because it thinks you are viewing a corrupt image file.

Test script:
---------------
Example of script that doesn't work because headers are being sent:
require_once("Image/Barcode.php");

function generate_barcode($sku) {
$filename = "/tmp/$sku.png";
if (!file_exists($filename)) {
ob_start();
Image_Barcode::draw($sku, "upca", "png");
$image = ob_get_contents();
ob_end_clean();
$file = fopen($filename, 'w');
fwrite($file, $image);
fclose($file);
}
}

function run(&$db,&$sysvars,&$output) {
$listings = array();
$query = "some query to get the items goes here";
$db->query($query);
while($db->next_record()) {
extract($db->record);
$data[] = array('cat'=>$category, 'sku'=>makesku($item_no), 'item_no'=>$item_no, 'item_des'=>$item_des);
generate_barcode(makesku($item_no));
}
$output['data']=$data;
}

function pdf(&$db,&$sysvars,&$output) {
include("generate_pdf_that_contains_barcodes.php");
run($db,$sysvars,$output);

generate_document($output['data']);
exit;
}

Expected result:
----------------
Barcode files are generated and saved to disk, pdf document loads those images and is displayed to the user.

Actual result:
--------------
Browser throws an error because it thinks that the PDF document is an image because Image_Barcode has already sent the wrong headers.

To fix it, I just commented out all of the header code in upca.php to make it work, but it would be nice if there was an official option to suppress the headers so that when I do an upgrade I don't have to dig through old code that is suddenly broken. Output to a variable would be even more desirable so that I don't have to mess with the output buffer.