Problem in View image from database...!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asad_black
Forum Newbie
Posts: 20
Joined: Wed Feb 11, 2009 1:59 am

Problem in View image from database...!

Post by asad_black »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hi this is my code which is retrieve image from the database bt problem is that my output comes in this form instead of image...!

GIF89a’÷¥¥¥¯¶Ót}Žúúúûûûÿþÿ¢ªÁ®µÒx’ßãîÈÌçÿÿýþþÿóóóôôô£­Æ`dgñññøøøïïïs|ëðì÷÷÷ìñíðððÇËæééé Ýáìþþüúüûûùúÿýÿ¤¬Ã¯¹ÒáçõÉÏÛËÌÞÞáò×Úßâéót|ˆ‹’ÇÊÝßáð†ˆ”ù÷ø°ºÓ¡ª¯õõõìñ÷dhk¡©Àx€“òòòÙàòhlofjmiq„ËÒØ³³³™¤º¨«²õ÷ößæö¬²¾¤¦³ÊÊÊßåñnnneilÝáä­±½õòù¥¼“š¬Ÿ§ºÁÄ×ÓÜáu}x‡”œ³ÍÐá§°·T[now„ÀÆÜdmvêî÷°·¿ØÛà«««bfi¶½Ð¯·Î¯µÅ¦°Éþÿÿaeh½ÂÖýýÿÊÍÔ˜Ÿ¯áä÷¿ÇÜÓØì³»ÐÕÛéòòúö÷ùÍÔäçççêïòÍÍÍãêò÷øúÖÜêýýûÉÉÉzzzâéñðï÷¾¾¾øùýççñùøþlllæíõæææýûÿˆˆˆèèòðô÷ssstttïîöø÷ýÚâïøö÷Ýãïíïî¡¡¡éîñúøùïóö÷õúþýûîðïøöûrrrÞäðöööÀÀÀ½½½çìïÿþü‹‹‹’’’Ð×ç{{{ÙáîËËËŠŠŠùúþóöû‘‘‘æëîÂÂÂÌÌÌíííìììÏÖæÃÃÃÿýþ”””ÄÄÄèè艉‰ðòñþüÿñóòóóûåìôòõúÌÓãùûúüüþ°·Ô¤¤¤u~£«ÂÆÊåÞâíùùùíòîüüüýýýþþþÿÿÿ!ù,’ÿ'Xˆð†G‘O[6ôZȰ¡Ã‡#Jœ(€Å‹3jÜȱ£Ç‹7l¹S„ 1&\J*V#LjÅ$F³¦Í›8sêÜÉSg±Ÿ@ƒ J´¨Ñ£@qÆ<Ö`ƒ !ª$DbèÕ1 ÂŽM8Ƶ«×¯`ÊK¶¬Ù³hÓŠÝ*LÃ1V…ì4€ÕIÏWc=óêÝk“€ß¿€,˜¯áÃ:}ÍTJ&N\#s0@­å˘3kÆ,¬Á1 \E¢çX ÇŠ#`¬µë×°cËžM»¶íÛ¸sëžM`©Ð¨\ùqÐûXÖÍÈ“+_nÖ˜ÅÂlTÊQ z®Â0ßν;Ú0׏Yÿ/c†‹GˆcÀ^ìî÷ðãËŸï,{2Å|p¡h†˜1H@ŒbÞhà]C€Ø “Ôòƒ,`álf¨!X±Y¸@ºü #@ „ÌáA1l2R0Æ(ãŒ4ÖHcl’ÔQŒm@âˆ)p!Ç22 Õm¨ä’eÐÊ.{à"Ã-xpaD"– €…-}ÌBQL†éÝP ‚X °(Fàà†'t3HIPBaÂä©çž|öé矀*è „ èD’Ä!|p°Æ*¹à ‚,”°Â&Œ@D\0̧Ãx ꨤ–jꩨ¦ªêª¬¶Úêœÿ1‚ g¬P B¨àC HHÑÄiÜÁ“À±Ç«ì²Ì6ëì³ÐF+í´ÔV-²ÅrÄ iŒÑ„H´àCPñEVx¡À“ð*A»ôÖkï½øæ«ï¾üöëï¿ûÆ;/0h¨á…]|eœÃf0Å ˆp@ð¢±ÆwìñÇ òÈ"ƒlrǧÌËÉ'«ìòË0Ç,3Ì!‹ðÀ Q0aÆ0œ …STñ„`<Ð üòKJ7íôÓO õÔRCmõÕXg­õÖ\w½´ÒÐÐÃ`(ñDS8¡Å;dAÂTèB P €¾ørwÞ|÷-íwÞ.xàÎ÷݈#n¸á‰'Îxã{/.yß‘ß]w )è@Å$d±Ã;


i dont know whatz the problem...!
kindly help me as soon as possible...!

this is my code

Code: Select all

 
<?php
 
 
// database connection
$conn = mysql_connect("localhost", "sample", "sample")
OR DIE (mysql_error());
@mysql_select_db ("sample", $conn) OR DIE (mysql_error());
$sql = "SELECT * FROM pix";
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array ($result);
$image_type = $row["title"];
$image = $row["imgdata"];
//Header ("Content-type: $image");
print $image;
}
?>

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Problem in View image from database...!

Post by Ziq »

You should send Content-type header first. In this case you have a GIF image and you should send

Code: Select all

 
<?php
header('Content-type: image/gif');
 
//...
 
asad_black
Forum Newbie
Posts: 20
Joined: Wed Feb 11, 2009 1:59 am

Re: Problem in View image from database...!

Post by asad_black »

its not work :(
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Problem in View image from database...!

Post by Ziq »

What do you have in output now?

Post full code please.
asad_black
Forum Newbie
Posts: 20
Joined: Wed Feb 11, 2009 1:59 am

Re: Problem in View image from database...!

Post by asad_black »

<?php
Header("Content-type: image/jpeg");
$con = mysql_connect("localhost","sample","sample");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$sql = mysql_query("SELECT * FROM pix");
//$result = mysql_query("SELECT * FROM image_table");
while($row = mysql_fetch_array($sql))
{
echo $row['title'];
echo $row['imgdata'];
echo "<br />";
}
mysql_close($con);
?>

my problem almost solved now i want to display title of image as well..!
but it show only image
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Problem in View image from database...!

Post by Ziq »

You cannot just echo a title. You should create 2 separeted scripts. First to show some info and second to show an image. Then you can using something like this

Code: Select all

 
<img src="second_script.php?some=variables">
 
It's one of the common method.

Of course you can use something like MHTML to show all informatiod using one script. But I think it's not good idea.
asad_black
Forum Newbie
Posts: 20
Joined: Wed Feb 11, 2009 1:59 am

Re: Problem in View image from database...!

Post by asad_black »

if u do this in code then i will be very thankful of u...!
Post Reply