Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Help Needed In Displaying Images From Mysqldatabase

extract mysql

  • Please log in to reply
1 reply to this topic

#1 jane

jane

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:C, Java, Objective-C
  • Learning:PHP

Posted 10 June 2012 - 03:23 PM

Hello i am new to php: i am unable to display the image that is saved in mysql properly. broken image icon is displayed that tells me that the image is extracted from the data base but its not displaying as html can any one help.

thank you in advance
// i got this code
{
// the id is the primary key from my database where the image is stored as blob....

$id = 39;

if(!isset($id) || empty($id) || !is_int($id)){
die("Please select your image!");
}else{

$query = mysql_query("SELECT * FROM store WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
echo $content;
  • 0

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 11 June 2012 - 05:04 PM

i think, ir order to debug the case , first you have to do is discard problems, so firstie is to make sure you have a good image in your database, and that you are extracting it properly.

so why don't you save $content in a file (bynary), like image.jpg, and try to read it with your windows image viewer ?

i have never did this on php / mysql , but i've done it in .net or c, against oracle and mssql, and it is always about codification, since the blob is binary, packet as database is configured, you need to read it in the same byte configuration in order to get the right image, cause there is byte translation in between database and client language, you need to sincronize that.

please, make me know if you have more specific data, see you
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download