jester18 Posted January 12, 2010 Share Posted January 12, 2010 hello all, Complete noob when it comes to PHP and MYSQL anyway I have put a series of images in my database, when trying to retrieve the images I just get a page of binary. <?PHP $link = mysql_connect("****","*****",""); mysql_select_db("***"); $query = "SELECT image,year,image_name,description FROM gallery"; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<images>\n"; while($line = mysql_fetch_array($results)) { echo "<photo>" . $line["image"] . $line["image_name"] . $line["year"]. $line["description"] . "</photo> \n"; } echo "</images>\n"; mysql_close($link); ?> Anyone know what the issue could be? Thanks all Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/ Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 You should define the header: Content-type: image/png to display the image, refer to the image functions in the PHP manual on how to deal with them. Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/#findComment-993331 Share on other sites More sharing options...
jester18 Posted January 12, 2010 Author Share Posted January 12, 2010 Many thanks tried to do as you suggested most likely I'm doing this completely wrong the error im getting; Warning: Cannot modify header information - headers already sent by line 24 <?PHP $link = mysql_connect("***","****",""); mysql_select_db("***"); $query = "SELECT image,year,image_name,description FROM gallery"; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<images>\n"; while($line = mysql_fetch_array($results)) { echo "<photo>" . $line["image"] . "</photo>\n"; echo "<photoname>" . $line["image_name"] . "</photoname>\n"; echo "<photodes>" . $line["description"] . "</photodes>\n"; echo "<photoyear>" . $line["year"] . "</photoyear>\n"; } header("Content-type: image/jpeg"); echo "</images>\n"; mysql_close($link); ?> Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/#findComment-993387 Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 I see what you are doing now. Why are you echoing an image into an xml file? The XML file should be text only, were you wanting to display the image name in place of the physical image itself? Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/#findComment-993393 Share on other sites More sharing options...
jester18 Posted January 12, 2010 Author Share Posted January 12, 2010 Oh right I see, I wanted to display the physical image along with the details of the image and get PHP to output the XML so that Flash actionscript can read the XML. Thanks, sorry if I'm way off still learning all of this. Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/#findComment-993406 Share on other sites More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 Oh right I see, I wanted to display the physical image along with the details of the image and get PHP to output the XML so that Flash actionscript can read the XML. Thanks, sorry if I'm way off still learning all of this. This can't be done, as if you were even to attempt to parse XML with a binary image within it'd come up with an obvious error as so. The only way you can do this is to link to the image within the xml file, for actionscript to read. Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/#findComment-993408 Share on other sites More sharing options...
jester18 Posted January 12, 2010 Author Share Posted January 12, 2010 Thanks very much for your help and paitence I think I got this now! Quote Link to comment https://forums.phpfreaks.com/topic/188151-image-display-issue/#findComment-993410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.