Subject | RE: [firebird-php] Show on browser blob saved images |
---|---|
Author | Nigel Weeks |
Post date | 2005-11-28T22:15:45Z |
> Hi,Have you received an answer to this yet?
>
> I need to show saved images in blob fields on browser, using PHP 4.
>
> Any hints, tips or links are welcome.
>
> I´m using PHP 4 x Firebird 1.5
>
> Thk
>
> Moacir
If not, consider the following:
CREATE TABLE tbl_blobimage (
int_image INTEGER NOT NULL,
str_filename
str_mimetype VARCHAR(20) NOT NULL, /* image/jpg, image/png, etc */
blb_imagedata BLOB,
PRIMARY KEY(int_image)
);
------ PHP to get a list of files (list.php) --------
<?php
// connect to the DB
$conn = ibase_connect("server:/path/to/database.fdb","sysdba","masterkey");
// Get a list of images
$sql = "select int_image, str_filename, str_mimetype FROM tbl_blobimage
order by str_filename";
// Run the query, and get a recordset
$rec = ibase_query($sql);
// Walk through the recordset
while($obj = ibase_fetch_object($rec)){
// Produce links to the images
echo "<a
href='image.php?id=".$obj->INT_IMAGE."&mime=".$obj->STR_MIMETYPE."'>".$obj->
STR_FILENAME."</a><br>";
// Show the images right here
echo "<img
src='image.php?id=".$obj->INT_IMAGE."&mime=".$obj->STR_MIMETYPE."'><br>";
}
?>
------ PHP based image renderer (render.php) -------
<?php
if($mime == "" || $id == ""){
echo "You need to specify a mime type and/or an image id<br>";
} else {
header("Content-type: ".$mime);
// connect to the DB
$conn =
ibase_connect("server:/path/to/database.fdb","sysdba","masterkey");
// Query for the binary data
$sql = "select blb_imagedata from tbl_blobimage where int_image =
'".$id."'";
$rec = ibase_query($sql);
$obj = ibase_fetch_object($rec,IBASE_FETCH_BLOBS); // Note the extra
argument!
// pump out the binary data to the browser
echo $obj->BLB_IMAGEDATA;
} // End of the $mime and $id supplied check
?>