Problem in View image from database...!

  • asad_black
  • Graduate
  • Graduate
  • asad_black
  • Posts: 131
  • Loc: pakistan

Post 3+ Months Ago

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

<?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;
}
?>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

Try this...
PHP Code: [ Select ]
<?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/gif');
print $image;
}
?>
  1. <?php
  2. // database connection
  3. $conn = mysql_connect("localhost", "sample", "sample")
  4. OR DIE (mysql_error());
  5. @mysql_select_db ("sample", $conn) OR DIE (mysql_error());
  6. $sql = "SELECT * FROM pix";
  7. $result = mysql_query ($sql, $conn);
  8. if (mysql_num_rows ($result)>0) {
  9. $row = @mysql_fetch_array ($result);
  10. $image_type = $row["title"];
  11. $image = $row["imgdata"];
  12. header('Content-Type: image/gif');
  13. print $image;
  14. }
  15. ?>


// Don't forget about the [code] tags...
  • asad_black
  • Graduate
  • Graduate
  • asad_black
  • Posts: 131
  • Loc: pakistan

Post 3+ Months Ago

thankx
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

Your welcome. I assume that the problem is fixed now?
  • asad_black
  • Graduate
  • Graduate
  • asad_black
  • Posts: 131
  • Loc: pakistan

Post 3+ Months Ago

my last problem has been solved but now my another problem is i want to display the title of the image as well as the description of the image.

<?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 where pid=1");
//$result = mysql_query("SELECT * FROM image_table");
while($row = mysql_fetch_array($sql))
{
echo $row['title'];
echo $row['description'];

echo $row['imgdata'];
echo "<br />";
}
mysql_close($con);
?>

but its show only image...!
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

You can do this like this.

Have a PHP page that gets the image... than use the img HTML tag to retrieve it... the HTML img tag would look something like...
Code: [ Select ]
<img src="images.php?pid=4" alt="Image" />

And then in that page, where you are retrieving the image (In the example above, (I am talking about images.php) you would have something like
PHP Code: [ Select ]
<?php
Header("Content-type: image/jpeg");
$pid = ((is_numeric($_GET['pid']) ? mysql_real_escape_string($_GET['pid']) : 1);
$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 where pid=" . $pid);
 
$row = mysql_fetch_array($sql);
 
return $row['imgdata'];
 
mysql_close($con);
?>
  1. <?php
  2. Header("Content-type: image/jpeg");
  3. $pid = ((is_numeric($_GET['pid']) ? mysql_real_escape_string($_GET['pid']) : 1);
  4. $con = mysql_connect("localhost","sample","sample");
  5. if (!$con)
  6. {
  7. die('Could not connect: ' . mysql_error());
  8. }
  9. mysql_select_db("sample", $con);
  10. $sql = mysql_query("SELECT * FROM pix where pid=" . $pid);
  11.  
  12. $row = mysql_fetch_array($sql);
  13.  
  14. return $row['imgdata'];
  15.  
  16. mysql_close($con);
  17. ?>

And then in the page where you are calling you'll have something like.
PHP Code: [ Select ]
<?php
$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 where pid=1");
//$result = mysql_query("SELECT * FROM image_table");
while($row = mysql_fetch_array($sql))
{
echo $row['title'];
echo $row['description'];
echo "<br />";
}
mysql_close($con);
?>
<img src="images.phppid=1" alt="Image" />
  1. <?php
  2. $con = mysql_connect("localhost","sample","sample");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. mysql_select_db("sample", $con);
  8. $sql = mysql_query("SELECT * FROM pix where pid=1");
  9. //$result = mysql_query("SELECT * FROM image_table");
  10. while($row = mysql_fetch_array($sql))
  11. {
  12. echo $row['title'];
  13. echo $row['description'];
  14. echo "<br />";
  15. }
  16. mysql_close($con);
  17. ?>
  18. <img src="images.phppid=1" alt="Image" />

Hope that makes sense and that it works :) I haven't tested it so there may be some syntax errors or it just may not work...

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 134 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.