Jump to content

showing a blob image from mysql


clowny

Recommended Posts

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 by clowny
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.