0

I'm using a third party php class to talk to UPS and generate a label. The generated label data comes in the Base64 format and I can display it like this.

echo '<img src="data:image/gif;base64,'.$label_data.'" />';

I'm just looking for a way to force this image to be downloaded (as a GIF) instead of just displaying it.

Any idea how this is possible?

farjam
  • 2,089
  • 8
  • 40
  • 77
  • possible duplicate of: http://stackoverflow.com/questions/5648967/force-download-image – JimL Jun 25 '13 at 20:49

1 Answers1

2

Since you already have the data, just output the headers and then the data!

<?php
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header("Content-type: application/force-download"); // or application/octet-stream
header('Content-Disposition: attachment; filename="ups.gif"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
echo $label_data;
exit;
?>
Rob W
  • 9,134
  • 1
  • 30
  • 50