clowny Posted January 21, 2013 Share Posted January 21, 2013 (edited) Hi all. I have what should be a super simple one, but it has me stumped. probably a minor syntax error or something... anyhow, i simply want to be able to call up a record that has a BLOB containing an image and display it on my page. There are 100 tutorials on it, and I really thought i understood the code and it was simple. Wrote the picture fetching script, and it (as far as i can tell) pulls up all the data... i see the raw data from the blob if i just open up the fetch script. but when i insert the url of the same fetch script as the src for an image in the other page, it comes up with a red x (ie bad file). here is my fetching script (getPic.php): <?php header('Content-type: image/jpg'); require_once('Connections/myconnection.php'); $username = "myUsername";$password = "myPassword";$host = "localhost";$database = "myDatabase";mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $id = $_GET['id']; if(!isset($id) || empty($id)){ die("Please select your image!"); }else{ $query = mysql_query("SELECT * FROM testImage WHERE id=3"); $row = mysql_fetch_array($query); $content = $row['image']; echo $content; } ?> and here is the simple code that should show it (showTestImage.php) : <img name="" src="getPic.php?id=5" width="32" height="32" alt="" /> there's less than 20 lines of code involved and i'm pretty sure i'm doing exactly what all the tutorials say.... ideas? Edited January 21, 2013 by clowny Quote Link to comment https://forums.phpfreaks.com/topic/273430-showing-a-blob-image-from-mysql/ Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 Take out the image header and see what is echod. in the future, store files in the filesystem. Quote Link to comment https://forums.phpfreaks.com/topic/273430-showing-a-blob-image-from-mysql/#findComment-1407271 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2013 Share Posted January 21, 2013 You apparently have a new-line before your <?php tag. You would be getting a header error if you had php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on your development system. Quote Link to comment https://forums.phpfreaks.com/topic/273430-showing-a-blob-image-from-mysql/#findComment-1407293 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.