Jump to content

Problem in View image from database...!


asad_black

Recommended Posts

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!Ç22 Õ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;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/144742-problem-in-view-image-from-database/
Share on other sites

I made this file to return an image from a database (i use this with an mssql database, so ive just chagned the commands from mssql_ to mysql_, i think it should work the same.

 

Just amend the query and connection string for your own settings and it should work

 

<?php
session_start();

if($_SESSION['loggedIn']){

	require("settings.php");

	$imageID = $_GET['imageID'];

	$connection = mysql_connect($server, $username, $password)
		or die ("Unable to connect to server");

	$db = mysql_select_db($database, $connection)
		or die ("Unable to select database");

	$sqlString1 = "SELECT image FROM images WHERE imageID = $imageID";

	$sqlResult1 = mysql_query($sqlString1, $connection) 
		or die ("Unable to run query. Error ID 1!");

	$row = mysql_fetch_assoc($sqlResult1);

	$imagebytes = $row['image'];

	header("Content-type: image/jpeg");

	print $imagebytes;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.