jacobs Posted March 27, 2006 Share Posted March 27, 2006 Hello everyone, I been trying to load an image from a mysql database using php. The code that I have works fine but once I change background color of the page or add an html table, the jpg picture won't appear and instead it appear as character like ÿØÿàJFIFHHÿÛC Could it be because of configuration in php.ini? Any suggestion I would really appreciate it. I am using iis for the webserver. I really appreciate your help. Thanks in advanceHere are the code that I havesession_start(); $id = $_POST['id']; // you may have to modify login information for your database server: @MYSQL_CONNECT("localhost","xxxxx","xxxxx"); @mysql_select_db("wip"); $query = "select content,type from data where fileid = '$id'"; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,"content"); $type = @MYSQL_RESULT($result,0,"type"); Header( "Content-type: $type"); echo $data;?> Quote Link to comment https://forums.phpfreaks.com/topic/5907-help-how-to-show-single-image-from-mysql-database/ Share on other sites More sharing options...
redbullmarky Posted March 27, 2006 Share Posted March 27, 2006 hithere are a couple of things to check. 1, above all the random characters, can you see any error messages?2, before this section:[code]Header( "Content-type: $type");echo $data;[/code]type:[code]echo 'results: '.mysql_num_rows($result);echo '<br>';echo 'type: '.$type;exit;[/code]you're looking for a non-zero number for result, and a correct MIME type (if $type is set from when the file was first uploaded from $_FILES['myfile']['type'] then it should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/5907-help-how-to-show-single-image-from-mysql-database/#findComment-21112 Share on other sites More sharing options...
jacobs Posted March 27, 2006 Author Share Posted March 27, 2006 Hello, thanks for the reply. Well above the random character, I did not see any error. Once I removed the changes I made the picture will be shown on the screen but in a really simple page format (white background and the picture itself). Do you think I have to encode the image ( I am using longblob type - I am saving the image into mysql database)? Do you have a simple example of how to load data from mysql? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/5907-help-how-to-show-single-image-from-mysql-database/#findComment-21114 Share on other sites More sharing options...
redbullmarky Posted March 27, 2006 Share Posted March 27, 2006 [!--quoteo(post=358807:date=Mar 27 2006, 09:42 AM:name=jacobs)--][div class=\'quotetop\']QUOTE(jacobs @ Mar 27 2006, 09:42 AM) [snapback]358807[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hello, thanks for the reply. Well above the random character, I did not see any error. Once I removed the changes I made the picture will be shown on the screen but in a really simple page format (white background and the picture itself). Do you think I have to encode the image ( I am using longblob type - I am saving the image into mysql database)? Do you have a simple example of how to load data from mysql? thanks in advance[/quote]youre pretty much doing it right, but remember that this script should only be used by calling it from elsewhere, and should not be embedded into your main scripts. so if the file you have got here is, eg, image.php, then you will need to call it via:[code]<img src='image.php?id=3' />[/code]if you have this script inside a page that also draws other items, notably Tables, etc, then it will not work as Headers need to be sent BEFORE any other content goes to the browser. change $_POST to $_GET in your file, and call it as i shown you above. Quote Link to comment https://forums.phpfreaks.com/topic/5907-help-how-to-show-single-image-from-mysql-database/#findComment-21117 Share on other sites More sharing options...
jacobs Posted March 28, 2006 Author Share Posted March 28, 2006 redbullmarky thank you for the help. Problem is now solved. Really appreciate your help[!--quoteo(post=358810:date=Mar 27 2006, 04:03 AM:name=redbullmarky)--][div class=\'quotetop\']QUOTE(redbullmarky @ Mar 27 2006, 04:03 AM) [snapback]358810[/snapback][/div][div class=\'quotemain\'][!--quotec--]youre pretty much doing it right, but remember that this script should only be used by calling it from elsewhere, and should not be embedded into your main scripts. so if the file you have got here is, eg, image.php, then you will need to call it via:[code]<img src='image.php?id=3' />[/code]if you have this script inside a page that also draws other items, notably Tables, etc, then it will not work as Headers need to be sent BEFORE any other content goes to the browser. change $_POST to $_GET in your file, and call it as i shown you above.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/5907-help-how-to-show-single-image-from-mysql-database/#findComment-21413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.