ryland22 Posted July 13, 2008 Share Posted July 13, 2008 I am making an xml request of usps.com to get a shipping label as a base64 encoded tiff image. They are sending back the data as a base64 encoded string. I take the string and insert it into a mysql database. When I try to display the tiff, I get a ton of random symbols, letters, crap. This is the code I have tried so far: <? $query = "SELECT label FROM table WHERE custid = ".$_GET['custid'].""; $result = mysql_query($query); $data = mysql_fetch_row($result); $USPSlabel = $data['label']; <img src="data:image/tiff;base64,<?=$USPSlabel?>"> ?> I also tried: <? $query = "SELECT label FROM table WHERE custid = ".$_GET['custid'].""; $result = mysql_query($query); $data = mysql_fetch_row($result); $USPSlabel = $data['label']; <img src="<?=base64_decode($USPSlabel)?>"> ?> Lastly I tried: <? $query = "SELECT label FROM table WHERE custid = ".$_GET['custid'].""; $result = mysql_query($query); $data = mysql_fetch_row($result); $USPSlabel = $data['label']; <?=base64_decode($USPSlabel)?> ?> Any ideas or suggestions? Link to comment https://forums.phpfreaks.com/topic/114574-base64-encoding-an-image/ Share on other sites More sharing options...
Lodius2000 Posted July 13, 2008 Share Posted July 13, 2008 i would think that <img src="<? echo 'base64_decode($USPSlabel)' ?>"> might do it, base64_decode($USPSlabel) just performs the function on the variable but doenst output anything, echo outputs EDIT: regardless if the function does what is needed, echo will most likely need to be in there, so leave it there and then get the function right, as i dont know what base64_decode does (looking it up right now) Link to comment https://forums.phpfreaks.com/topic/114574-base64-encoding-an-image/#findComment-589137 Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2008 Share Posted July 13, 2008 Each image on a web page requires a HTML <img src="url_of_the_image" alt=""> tag - http://www.w3schools.com/html/html_images.asp. The url_of_the_image from the scr="..." parameter is fetched by the browser. This would be to your php file that is selecting the data and performing the base64_decode. When that page is requested, it needs to output a proper Content-type: header for the image type, followed by the image data. Base64 encoded data requires more storage than binary data (and TIFF images are even larger than images using compression, like .jpg or .gif). You should actually perform the base64 decoding when you receive the image and store it in binary in a blob field in the database. This will require the least amount of storage and provide the greatest performance. Link to comment https://forums.phpfreaks.com/topic/114574-base64-encoding-an-image/#findComment-589149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.