downah Posted April 1, 2012 Share Posted April 1, 2012 echo '<img src="data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . '" height="150" />'; This is showing up images great in firefox, safari and chrome, but in internet explorer it shows a nice red cross, and I assume it is because of the encoding? Does anyone know how to get working in internet explorer as well? Pretty urgent job! Much appreciated for your help! Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/ Share on other sites More sharing options...
TimeBomb Posted April 1, 2012 Share Posted April 1, 2012 This does look like an IE restriction. There are multiple different ways to remedy this, as you will find through a simple google search. Looking through the first page, Dean Edwards fix seems like it should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333247 Share on other sites More sharing options...
PFMaBiSmAd Posted April 1, 2012 Share Posted April 1, 2012 Since it prevents the browser from caching the images, you should not be outputting images on a web page this way. It also results in a huge amount of data which slows down the sending and loading of the web page (base64 encoding is always larger than the raw image data.) Do you have a specific reason for trying to output the image this way? Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333275 Share on other sites More sharing options...
downah Posted April 1, 2012 Author Share Posted April 1, 2012 Nope it was the first working thing I found to display my image from the blob field, if you have other suggestions please do tell! I did notice a slower process when loading pages with images! Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333372 Share on other sites More sharing options...
PFMaBiSmAd Posted April 1, 2012 Share Posted April 1, 2012 To dynamically output images from php, you normally use a separate .php script to output the actual image data. You would put the URL of this separate .php script into the src="URL_of_script_that_outputs_an_image" attribute. The main page would just form the correct URL and put it into the src="..." attribute. The query in the main page would not SELECT the raw image data, but would instead select the ID of the image. You would typically put a GET parameter on the end of the URL to specify the id of the image (so that you can use the same .php script for any dynamically produced image.) The <img tag would end up looking like - <img src="image.php?id=123" alt=""> This separate .php script would read the GET parameter $_GET['id'], validate it/cast it as an integer (since it is going to be put into a mysql query), form and execute a query that gets the content-type of the image (you can either store this in the database table row with the blob image data or you can use the image file extension to get the correct content type) and the raw image data. You then output a content-type header followed by the image data. You should be able to find an example showing this now that you know the general process. Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333383 Share on other sites More sharing options...
PFMaBiSmAd Posted April 1, 2012 Share Posted April 1, 2012 Sample code to dynamically output an image - <?php // file called using <img src="image.php?id=123" alt=""> $id = isset($_GET['id']) ? intval($_GET['id']) : false ; // get and condition id, setup default if id not supplied // setup default type/image in case of error (no id, invalid id, no matching image, query error) $type = 'image/jpg'; $default = 'error.jpg'; // assumes you have an error image file if($id > 0){ // make db connection and select db mysql_connect('localhost','your_dbuser','your_dbpwd'); mysql_select_db('your_db'); // query for the image mime type and image data $query = "SELECT type,image FROM your_table WHERE id = $id"; $result = mysql_query($query); if(mysql_num_rows($result)){ // query worked and image found list($type,$image) = mysql_fetch_row($result); } } // output the actual image or the default/error image header("Content-Type: $type"); if(isset($image)){ echo $image; } else { readfile($default); } Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333402 Share on other sites More sharing options...
downah Posted April 2, 2012 Author Share Posted April 2, 2012 But then I would need two ID's? I have one field Image (blob) in the Member table, how would it know when to show the right one? Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333708 Share on other sites More sharing options...
PFMaBiSmAd Posted April 2, 2012 Share Posted April 2, 2012 If the row has an id, that is the id value you would use. What makes you think you would need two ids? Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1333710 Share on other sites More sharing options...
downah Posted April 9, 2012 Author Share Posted April 9, 2012 I see, the script does not work though, neither when I go to image.php and set the id to a member Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1335587 Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2012 Share Posted April 9, 2012 does not work We cannot help you with vague statements about something that does not work. We are not standing right next to you and did not see what you saw when you tried something and contrary to popular belief, the P in HTTP does not stand for Psychic. We don't know what your code is, what your data is, what you did, what result you got, and what result you expected. Without the code that reproduces the problem and a statement or picture of what result you got, and the actual data your code was using, we cannot help you. Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1335649 Share on other sites More sharing options...
downah Posted April 9, 2012 Author Share Posted April 9, 2012 It was about the script above it, so the code was there either way I fixed it so thanks to everyone who tried to help Quote Link to comment https://forums.phpfreaks.com/topic/260123-base64-encode-image-blob-not-showing-in-ie/#findComment-1335659 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.