2013-06-25 33 views
0

我正在使用第三方php類來與UPS對話並生成標籤。生成的標籤數據採用Base64格式,我可以像這樣顯示它。強制生成的UPS標籤下載

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

我只是想找到一種方法來強制下載(作爲GIF)而不是隻顯示它的圖像。

任何想法如何這是可能的?

+0

可能的重複:http://stackoverflow.com/questions/5648967/force-download-image – JimL

回答

2

由於您已經擁有數據,只需輸出標題,然後輸出數據!

<?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; 
?>