Solved

error in loading image in php version 5

Posted on 2007-03-29
8
213 Views
Last Modified: 2013-12-13
hi,
I have written this code to show image stored in mysql db :

<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv=pragma content=no-cache>
<meta http-equiv=cache-control content=no-cache>
<meta http-equiv=expires content=0>
<meta content="" name=Keywords>
<meta content="" name=Description>
<TITLE>Home Page</TITLE>

</HEAD>


<BODY >
<div id="toprightdiv" style="margin-left:250px; width: 602px; height: 522px">
<hr color = #800000      >
<div style = "margin-left:100px;">
<a href = "delete.php" >Delete a project</a><span style = "margin-left: 190px;"></span>
<a href = "add.html" >Add new project</a>
</div>
<br>
<?php
     require($_SERVER['DOCUMENT_ROOT'] . '\config\db_config.php');
      $link = mysql_connect($db_host, $db_user, $db_password);
      mysql_select_db($db_name,$link);
      $img0 = array();
      $project = array();
      $projects = mysql_query ("SELECT * FROM project order by project_date", $link) or die (mysql_error());
      //echo mysql_num_rows($projects);
      for ($i = 0; $i < mysql_num_rows($projects); $i++)
      {
      //echo "<br>$i<br>";
       array_push($img0,mysql_result($projects, $i, "img0"));
       array_push($img0,mysql_result($projects, $i, "project_name"));
      }
     
 /*   for  ($i = 0; $i < count($img0); $i++)
      {
          echo "$img0[$i]<br>";  
      }*/
    /*   $table_res = '<table   style = "width:250px;" >';
       echo "$table_res";
      $number_of_thumbs_in_row = 3;*/
     
       $q="SELECT * FROM `img_pg` WHERE `img_name`='$img0[0]'";
       $res=mysql_query($q) or die (mysql_error());
       
       echo mysql_num_rows($res);
      if ($res && (mysql_num_rows($res) > 0) )
      {

     //echo "test";
     $row=mysql_fetch_array($res);
     $data = $row["img_data"];
     $type = $row["img_type"];
     $size = $row["img_size"];  

      }
      //echo "$type";
   Header( "Content-Type: $type");
   Header( "Content-Length: $size");
   echo $data;

?>


</div>
</BODY>
</HTML>
(note I am using gd2 library)
but the problem whenever I load this page, instead of image loaded I've got symbols .. just like :

2&#1746;&#1591;&#1746;àJFIFdd&#1746;&#1609;Ducky &#1746;îAdobed&#1729;&#1746;&#1594;„''2&&2.&&&&.>55555>DAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDD  &&6& &6D6++6DDDB5BDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD&#1746;&#1729;TK"&#1746;&#1572;&#1681;!1AQaq"&#1662;‘2&#1548;±&#1569;&#1585;&#1604;BR#&#1611;br‚3&#1612;’¢&#1586;“²CS$cT!1AQaq‘"2B&#1662;&#1585;&#1612;Rb#&#1746;&#1593; ?&#1609;•‹ ‰ &#1573;‘:&#1662;™&#1662;‹ &#1581;,"ˆ”’)®&#1575;‘+Ma#N&#1573;O¤Fée&#1570;°u&#1618;ne&#1729;&#1613;ü"®Z)&#1688;c&#1662;–~ˆ&#1594;Nˆ&#8206;1! ^q&#1657;&#1613;½Q&#1726;&#1602;>Ml&#1594;>&#1548;4€5&#1587;Z&#1605; ¥1€&#1670;&#1577;c&#1588;  *&#1657;y&#1581;vnkShû"–§”²c€&#1672; (®“ˆ&#1670;\°—X=°Pc)&#1729;•0&#1570;&#1578;§&#1584;&[(&#1591;!ë &#1590;¦Z¯&#1726;Y–&#1613;Qƒ>&#1681;T&#1569;+&#1574;h+©Œ„ &#1586;0¬¶&#1548;ŒkX»¢‚&#1588;ŒMWYXµCmiù&#1672;&#1573;÷H&#1726; ic‹db¬¾™B&#1584; ½œ !¼e&#1670;&#1574;R8&#8206;1l[&#1688;p"™&#1575;&#1610;¨&#1584;{£E–¹&#1688;Cœb&#1726;&#1594;&#1569;F2&#1567;&#1657;&#1576;†_)$V’}&#1613; @-&#1729;"t:‚L,‰P’*It’@&#1569;§&#1570; ‘)!dq0iLx&#1574;&#1586; XI±¸kf¼f‹&#1580;»‘Q&#1612;&#1613;&#1705;q&#1579;œµ%r&#1570;iD2)Œ§:&#1705;&#1729;Vè£ç&#1729;&#1729;(&#1576;hr&#8204;F8.‹fiZ@ˆ&#1705;zNF ZdH&#1581;Q^#9û#Ub&#1711;&#1574;«L², e°ƒ«u™"€q1€ D&#1590;RB&#1591;RUu&#8205;y&#1579;z±&#1586;=±„W&#1578;D&‡:&#1571;&#1575;&#1570;)û @&#1584;&#1705;$&#1587;„Œy&#1573;&#1726;µ&#1580;)u© &#1681;…QW&#1582;-J&#1593;&#1579;>p&#1604;&B&#1548;÷)€>&#1569;&#1572;&#1722;(F’«&#1574; &#1657;&#1586;X&#1604;uP1M ZdGo&#1592;&#1600;ô‡R UD×&#1567;´N&#1576;²)-v&#1604;lp®&#1578;JfJ­&#1592;&#1594;&#1570;\&#1591;w &#1607;&#1657;_!&#1611;&#1726;&#1711;&#8206;Q;&#8207;&#1605;¹M&#1585;±a&#1570;&#1726;€O¥O&#1590; &#1610;&#1585;­¶¦RV­G&#1613;™”Z»r&#1615;&#1579;¥Z„&#1657;R—&#1610;&#1612;;?&#1594;ƒQ&#1602;o&#1579;›”@&#1572;&#1662;©l&#1613;W&#1746;&#8206;&#1579;&#1617;&#1575;&#8206;³¯&#1594;&#1616;&#1572;&#1601;—¶3X&#1590;u>]H÷EëW&#1726;–&#1606;&#1608;v&#1581;&#1585;&#1601;k&#1615;‹&#1662;t.°( S&#1589;7é&#1672;[Zp’t&#1580;&#1585;¸ ´&#1604;÷ë&#1563; &#1567;&#1603;k5'­î&#8204;™&#1608;»&#1579;‹&#8204;&#1574;&#1581;£’.¦&#1618;à&#1617;:&#1615;©±&#1662;·AIS½¼&#1583; ˆUVù&#1594;¤=J&#1662;Z&#1604;&#8204;D^&#8206;4îKN ×&#1610;&#1605;÷&#1575;.&#1600;mv·wdz&#1578;èO XNs&#8204;Oc¢&#1617;×l¬&#1617;&#1662;K&#1563;V &#1610;&#1609;p&#1576;&#1581;&#8204;×{wmn&#1602;&#1590;&#1589;&#1574;ê·&#1572;&#1746;›Hû&#1580;&#1571;&#1594;,¹i)&#1572;}&#1670;wûçaˆ®…&#8207;•‚¶5n”¯J&#1594;ˆ&#1593;&#1603;@÷¦&#1611;&#1593;Y·y&#1581;&#1574;¹p&#1567;«‚®S§´ g·^¸€–`B&#1662;&#1605;«&#1608;R&#1587;àQ+NZ±&#8205;³c¶j–&#1591;p¯¾+&#1616;&#1583;„b&#1581;.™_&#1582;ü{#&#1576;&#1610;Pm­y©Z#ï&#8204;K]&#1608;&#1601;&#1588;{vm&#1600;×&#1548;´&#1588;xxG÷­¥&#1670;&#1688;&#1593;&#1607;&#1606;R.0&#1584; O&#1722;&#1616;&#1602;&#1600;–.*&#1586;¾&Y«&#1672;S/^ê&#1594;¶&#1578;4I#›&#1594;U&#1616;:n&#1601;¶&#1606;($&#1584;c;[n&#1746;grâ&#1586;&#1594;u­q9 ¯½~&#1582;&#1586;&#1607;&#1586;q&#1587;A&#1610;&#1570;y&#1581;‡&#1610;mî&#1602;9¥£O6&#1570;_«&#1672;Qq&#1601;W{-t¬#>&#1572;³\7B—,&#1607;´Œ&#1582;3_s½y.=–´¨£x&#1581;&#1610;›½C&#1613;¯×¼Z&#1600;_6~[©F&#1585;¨·&#1604;&#1571;&#1722;'N&#1579;:&#1603;®µ¬&#1563;U©&#1581;î, &#1610;&#1609;ƒ&#1611;&#1594;&#1590;|&#1591;&#1577;¾&#1575;j„&#1726;°D&#1582;qc&#1609;@&#1600; }&#1610;&#1588;¶0R- &&#8205;&#1614;hm&#1594;o³\”&#1672;&#8206;F^_²i&#1590;¼&#1602;&#1594;µ&#1726;&#1591;q&#1573;&#1662;&#1604;Y?&#1594;£S¨&#8207;_¶j&#1594;X~ƒ¶“¤[$êü&#1573;&#1591;®t&#1726;ç&#1613;&#1593;v÷ DjN&#1594;[ûHû a&#1614;[û¤c&#1726;&#1608;&#1705;;‹&#1722;1½&#1563;ëˆ&#1588;Gô&#1604; ²|bë&#1611;&#1589;t&#1578;&#1609;&#1590;&#1593;&#1610;&#1589;jz‰fƒ&#1580;û³¥I&#8207;vû&#1670;&#1602;ûà–&#1610;&#1591;¸&#1726;®]‰&#1574;§&#1592;&#1600;-›Vl&#1592;qFgk„C;;&#1688;&#1618;½¾&#1612;&#1593;Z³¬¨!©‰&#1616;NOx½&#1614;&#1609;©&#1548;&#1606;&#1575;«G'&#1722;¥&#1592;ëׯ&#1605;kL&#8206; &#1586;7&#1591;W=^‘Z±&#1569;G°T&#1581;—{m&#1581;
0
Comment
Question by:Ameerh24
  • 4
  • 3
8 Comments
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18821064
Are you sending the proper headers? Without headers, this jpg is just data to the computer.
0
 

Author Comment

by:Ameerh24
ID: 18821622
of course .. if u look into code you will find :
   Header( "Content-Type: $type");
   Header( "Content-Length: $size");
0
 
LVL 4

Expert Comment

by:secondv
ID: 18822016
What's the field type for the field in the mysql table that holds the image data?
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18822357
Just asked, saw the code, but also saw the output.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Ameerh24
ID: 18822432
bolb ..
0
 

Author Comment

by:Ameerh24
ID: 18825205
sorry .. I mean blob datatype
0
 
LVL 23

Accepted Solution

by:
Stacy Spear earned 500 total points
ID: 18825683
Did you inspect what is being returned to the browser? Is it really getting the proper headers? I just want to eliminate that being thinking the data is stored incorrectly in the DB. Although, blob is the best datatype AFAIK.

firefox has a few extensions that allow you to view the requested and returned headers on items.
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18825689
Or post a link with a test image and I can look from my browser
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now