RE: [PHP-DB] storing images in database

From: Date: Tue, 25 Jan 2005 23:28:16 +0000
Subject: RE: [PHP-DB] storing images in database
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-38349@lists.php.net to get a copy of this message
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: 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:
yes goes back to the whole header problem which is why you are here. If you could post the code, it would be simpler to help you... Bastien
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
From: Chip Wiegand <chip.wiegand@simrad.com> To: bastien_k@hotmail.com Subject: RE: [PHP-DB] storing images in database Date: Tue, 25 Jan 2005 12:44:44 -0800 "Bastien Koert" <bastien_k@hotmail.com> wrote on 01/25/2005
12:39:15
PM:
Its not src='id=$id'> that will defnintely blow up.... echo '<img src="./path/to/image.php?id=$id">'; where $id is the id of the record you are trying to get the
image
to...
Bastien
So the code has to be a seperate included page I guess? -- Chip
From: Chip Wiegand <chip.wiegand@simrad.com> To: bastien_k@hotmail.com CC: php-db@lists.php.net Subject: RE: [PHP-DB] storing images in database Date: Tue, 25 Jan 2005 12:37:15 -0800 Thanks Bastien, In testing this I have added the code samples to a page and
have it
working except the path statement is not correct. For now, I've
just
added
all the code to one page, rather than including a second page.
The
statement - echo '<img src="id=$id">'; is resulting in this
error -
The
requested URL /id=$id was not found on this server. Any
suggestions?
Thanks, Chip "Bastien Koert" <bastien_k@hotmail.com> wrote on 01/25/2005
09:45:39
AM:
the best way to do this is to move the image processing code
to
a
separate
page and include it like this echo '<img src="./path/to/image.php?id=$id">'; then the image page looks like this: <?php if($_GET['id']) { $id = $_GET['id']; // you may have to modify login information for your
database
server:
@MYSQL_CONNECT("localhost","root","password"); @mysql_select_db("binary_data"); $query = "select bin_data,filetype from binary_data where
id=$id";
$result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,"bin_data"); $type = @MYSQL_RESULT($result,0,"filetype"); Header( "Content-type: $type"); echo $data; }; ?> bastien
From: Chip Wiegand <chip.wiegand@simrad.com> To: "PHP DB" <php-db@lists.php.net> Subject: [PHP-DB] storing images in database Date: Tue, 25 Jan 2005 09:11:07 -0800 I have stored a .jpg image in a database, then when I make
a
sql
statement
to display that image on a web page all I get is the
cryptic
code
in
place
of the image. I am storing it in a row configured as a
blob,
mime
type
image/jpeg and binary (using phpMyAdmin). What am I doing
wrong?
Regards, Chip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.db (#38349) next »