[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get image from MYSQL database

Posted on 2011-10-02
1
Medium Priority
?
295 Views
Last Modified: 2012-05-12
Hi,

I'm doing php coding and would like to know how to get images from MYSQL database.
I inserted a field( flag ) with BLOB data-type in countries table ( catid, catname, flag) but having problem fetching those images from DB. I tried to fetch but it gave me meaningless representation like this:
HDR\r¨f	pHYsšœ OiCCPPhotoshop ICC profilexڝSgTSé=÷ÞôBKˆ€”KoR RB‹€‘&*!	Jˆ!¡ÙQÁEEÈ ˆŽŽ€ŒQ,Š Øä!¢Žƒ£ˆŠÊûá{£kÖ¼÷æÍþµ×>ç¬ó³ÏÀ–H3Q5€©BàƒÇÄÆáä.@ $p³d!sý#ø~<<+"À¾xÓÀM›À0‡ÿêB™\€„Àt‘8K€@zŽB¦@F€˜&S `ËcbãP-`'æÓ€ø™

Open in new window


Here are the functions that I'm working on:
function get_countries() {
   // query database for a list of countries
   $conn = db_connect();
   $query = "select catid, catname, flag from countries";
   $result = @$conn->query($query);
   if (!$result) {
     return false;
   }
   $num_cats = @$result->num_rows;
   if ($num_cats == 0) {
      return false;
   }
   $result = db_result_to_array($result);
   return $result;
}

Open in new window


function display_countries($cat_array) {
  if (!is_array($cat_array)) {
     echo "<p>No countries currently available</p>";
     return;
  }
  echo "<ul>";
  foreach ($cat_array as $row)  {
    $url = "show_cat.php?catid=".$row['catid'];
    $title = $row['catname'].$row['flag'];
    echo "<li>";
    do_html_url($url, $title);
    echo "</li>";
  }
  echo "</ul>";
  echo "<hr />";
}

Open in new window

0
Comment
Question by:hmbargi
1 Comment
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 1000 total points
ID: 36899998
Try to tell the browser it is an image with a line preceding to the fetched image row:

header("content-type: image/jpg") ;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 1 hour left to enroll

873 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