Jump to content

Recommended Posts


Hey guys,

I've been trying to display some images stored in a mysql database. The upload script seems to work fine. My problem arises when i try to display the images.

I use two files, one called view.php and the other view_image.php.

The view.php file includes the following code.

$query = "SELECT mime_type,image FROM testblob2
WHERE id = 1";

//the image field is of type longblob and the mime_type field is of type varchar

$result = @ mysql_query ($query,$connection);

$data = @ mysql_fetch_array($result);

if (!empty($data["image"]))
{
// Output the MIME header
// header("Content-Type: {$data["mime_type"]}");
// Output the image
echo $data["image"];
}

When i pulled this script (view.php) through the browser i received the same output that you get when you open up an image file with a text editor. A bunch of weird symbols.

I then included the following code in the view_image.php file:

$query = "SELECT id,image_name FROM testblob2";

$result = @mysql_query($query,$connection);
if($row = @mysql_fetch_array($result))
{
echo "{$row["image_name"]}";
echo "<img src=\"view.php?file={$row["id"]}\">";
}

When i pull up view_image.php through the web browser i get a broken link where the image is supposed to be. I can't seem to resolve this issue.

I also would like to fully understand the line
echo "<img src=\"view.php?file={$row["id"]}\">";
Where does the word "file" come from since i can't find a line where it gets passed to the script and what is the function of the "?"

I guess its similar to the url above [a href=\"http://www.phpfreaks.com/forums/index.php?act=post&do=new_post&f=1\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...do=new_post&f=1[/a]

why is the word or value "act=post&do=new_post&f=1" used and where does it come from. Does it have to be passed to the script using GET or POST .

I'm just trying to pinpoint where i've gone wrong. I'm a relative newbie to php coding but i don't believe that retrieving and displaying an image from a database should be so frustrating. Must be something simple that i'm missing.

Another forum that i checked mentioned that a broken link for the image usually means that the header has not be sent. Should I be sending the filesize with the header as well .

I'm not debating whether or not I should have stored the absolute paths instead of storing the images in the databse as blobs. I'd just like to deal with the issue at hand. Displaying the images that are currently stored.
[!--quoteo(post=387388:date=Jun 24 2006, 02:49 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 24 2006, 02:49 AM) [snapback]387388[/snapback][/div][div class=\'quotemain\'][!--quotec--]
index.php?file=123

this passes info to index via the GET method. You can access it like so:

echo $_GET['file']; //prints out 123
[/quote]


Thanks Crayon Violent,

I'm sorry that I didn't respond sooner. I had to head out for the weekend. Got back in last night. Thanks for the info. I understand that aspect now. Do you have any ideas as to how to display the photos from the mysql database though?

I'd greatly appreciate a response


zobie
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.