Home > Archive > PHP DB > January 2005 > RE: [PHP-DB] storing images in database
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RE: [PHP-DB] storing images in database
|
|
| Bastien Koert 2005-01-25, 8:56 pm |
| And how are you feeding the $id?....are you setting a value for that
element?
In the sample code the default is the record_id that corresponds back to the
id of the row with the image blob field.
Bastien
>From: Chip Wiegand <chip.wiegand@simrad.com>
>To: bastien_k@hotmail.com
>CC: "PHP DB" <php-db@lists.php.net>
>Subject: RE: [PHP-DB] storing images in database
>Date: Tue, 25 Jan 2005 12:57:40 -0800
>
>"Bastien Koert" <bastien_k@hotmail.com> wrote on 01/25/2005 12:46:12 PM:
>
>
>This is in the main page -
><?
>printf("<p><img src=\"image-src.php?id=$id\" alt=\"hotspot
>images\">%s</p>", $row["text"]);
>?>
>and this is in a new included page -
><?
>if($_GET['id']) {
>$id = $_GET['id'];
>$query = "select * from hotspots where id=$id";
>$result = @MYSQL_QUERY($query);
>
>$data = @MYSQL_RESULT($result,0,"image");
>$type = @MYSQL_RESULT($result,0,"type");
>
>Header( "Content-type: $type");
>echo $data;
>};
>?>
>The database connection statements are in an include file called at the
>top of the main page. In the first statement shown above the alt text for
>the image appears on the web page just fine, the image itself shows a
>broken image icon. FWIW, I have the image stored in the database in a blob
>field, is that correct?
>--
>Chip
>
>PM:
>to...
>just
>The
>suggestions?
>09:45:39
>a
>id=$id";
>sql
>code
>mime
>wrong?
>
| |
| Chip Wiegand 2005-01-25, 8:56 pm |
| I have done it an easier way, and probably a better way all-around anyway.
I am storing the images in a directory and have the script call the
file/alt text/title text and a description text in a paragraph below the
image. It works quite well this way.
What I'm doing is on this home page there is a place for a 'hotspot', a
special mention area for the latest news about a particular item. So I
have a directory and in it will store an image file called 'latest.gif',
so any new image that gets put here will overwrite the existing image.
This will be fine for the purposes and the site.
Here is the code I have used -
<?
include "connect";
$sql="select * from hotspots";
$result = mysql_query($sql);
while ( $row = mysql_fetch_array($result))
{
printf("<p><img src=\"hotspots/latest.gif\" alt=\"%s\"
title=\"%s\"></p><p class=\"footnote\">%s</p>", $row["alt-text"],
$row["title-text"], $row["desc-text"]);
}
?>
I'm sure there are many ways to do this sort of thing, but this is quick
and easy, and works.
Thanks guys,
--
Chip
"Bastien Koert" <bastien_k@hotmail.com> wrote on 01/25/2005 01:06:01 PM:
> And how are you feeding the $id?....are you setting a value for that
> element?
>
> In the sample code the default is the record_id that corresponds back to
the
> id of the row with the image blob field.
>
> Bastien
>
>
>
>
PM:[color=darkred]
for[color=darkred]
blob[color=darkred]
12:39:15[color=darkred]
image[color=darkred]
have it[color=darkred]
The[color=darkred]
error -[color=darkred]
to[color=darkred]
database[color=darkred]
a[color=darkred]
cryptic[color=darkred]
blob,[color=darkred]
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
| |
| Bastien Koert 2005-01-25, 8:56 pm |
| Filesystem is easier, by far since it avoids the content header. Glad you
solved it
bastien
>From: Chip Wiegand <chip.wiegand@simrad.com>
>To: bastien_k@hotmail.com
>CC: "PHP DB" <php-db@lists.php.net>
>Subject: RE: [PHP-DB] storing images in database
>Date: Tue, 25 Jan 2005 14:32:11 -0800
>
>I have done it an easier way, and probably a better way all-around anyway.
>I am storing the images in a directory and have the script call the
>file/alt text/title text and a description text in a paragraph below the
>image. It works quite well this way.
>What I'm doing is on this home page there is a place for a 'hotspot', a
>special mention area for the latest news about a particular item. So I
>have a directory and in it will store an image file called 'latest.gif',
>so any new image that gets put here will overwrite the existing image.
>This will be fine for the purposes and the site.
>Here is the code I have used -
><?
>include "connect";
>$sql="select * from hotspots";
>$result = mysql_query($sql);
>while ( $row = mysql_fetch_array($result))
> {
> printf("<p><img src=\"hotspots/latest.gif\" alt=\"%s\"
>title=\"%s\"></p><p class=\"footnote\">%s</p>", $row["alt-text"],
>$row["title-text"], $row["desc-text"]);
> }
>?>
>I'm sure there are many ways to do this sort of thing, but this is quick
>and easy, and works.
>Thanks guys,
>--
>Chip
>"Bastien Koert" <bastien_k@hotmail.com> wrote on 01/25/2005 01:06:01 PM:
>
>the
>PM:
>for
>blob
>12:39:15
>image
>have it
>The
>error -
>to
>database
>a
>cryptic
>blob,
>
|
|
|
|
|