Subject Re: Show a Jpg stored as Binary blob in a firebird table with PHP
Author prom_prometheus
thank you Didier for you long answer ...

i) -> to handle blobs in Firebird (or Interbase) is for me no
problem, also not in Backup/Restore, i do it with word.docs, whole
Programms (for automatical updates) and so on ... since many years
-> so i will use this wonderfull database also for my php-apps.
Till now i used MySql for php-apps, but my whole software system is
based on firebird delphi client/Server applications (db size: 1.7GB,
60 high updating concurent users, etc.), so its clear to go with
firebird on php-apps too !!

ii) i tried now many things to show JPGs (blobs from db) with php,
but i had no success, my last trying:
------------------------------------------------------------------.)

class ibase_blob {
var $blobid;
var $length;
var $numseg;
var $maxseg;
var $stream;
var $isnull;
var $data;

function ibase_blob($blobid) {
$this->blobid = $blobid;
}

function retrieve_all() {
$this->retrieve_info();
$this->retrieve_data($this->length);
}

function retrieve_info() {
list($this->length,$this->numseg,
$this->maxseg,$this->stream,
$this->isnull)
=ibase_blob_info($this->blobid);
}

function retrieve_data($size='1024') {
$bl=ibase_blob_open($this->blobid);
if ($bl) {
while($buf = ibase_blob_get($bl, $size)) {
$this->data .= $buf;
}
ibase_blob_close($bl);
}
}
}

$sst = "SELECT GRUND_FOTO FROM GSE WHERE GID = 1";
$res = ibase_query($sst, $f);
if(empty($res)) echo SQL_error($f,$sst)."<BR>";
$rowx = ibase_fetch_row($res);

$bl = new ibase_blob($rowx[0]);
$bl->retrieve_data();

//---------------------
//here is the problem: till this step it seems to work ....
$foto = imagecreatefromstring($bl->data);
//---following comes: Warning: Data is not in a recognized format.
//--------------
imagejpeg($foto, "foto.jpg");
print "<img border='0' src='foto.jpg' width='512' height='384'>";
imagedestroy($foto);

uff, where is a way?
best regards
-Gerhard


--- In firebird-php@yahoogroups.com, "Didier Gasser-Morlay"
<Didiergm@n...> wrote:
> --- In firebird-php@yahoogroups.com, "prom_prometheus"
> <prometheus@a...> wrote:
> > Hello,
> > can someone help me?
>
> Can try ;) but this is more a PHP question than anything else.
>
> > I try to make a webpage (PHP4, Firebird 1.5 b3, Apace WEbserver)
> > and have the following problem:
> > show pictures that was stored in a table as binary blob
> > ...,
> > GID integer not null,
> > GRUND_FOTO BLOB SUB_TYPE 0 SEGMENT SIZE 80,
> > ...
> > echo row->grund_foto didn't work, smile ...
>
> 1°) have a look at http://php.weblogs.com/adodb -> REALLY good &
fast
> db wrapper. John Lim is a clever guy ! there is some support for
blobs.
>
> 2°) the answer mainly depends on your circumstances : hosting,
> standard or secure (HTTPS), your level of access to the host, what
you
> really intend to do (ie show the image as such, on it's own, or as
> part of a more complex layout (e.g. say it's a shot of a product
on a
> product page)
>
> In the long run, I believe that the simplest/more reliable would
be to
> 1- write the blob to disk as a file (xxx.jpg is it's a jpeg) and
> 2- send a HREF link to it as part of an IMG tag. this way your turn
> around a really difficult long standing IE bug when you try to PUSH
> some data to your user's browser.
>
>
> 3°) now, that being said ... you should also consider whether or
not
> is is worthwhile having the images INSIDE the db, and not simply
have
> a link to those, stored on disk. Again this depends on many factors
> but remember that blobs tend to ... bloat a db pretty swiftly,
making
> a backup & restore process that much more difficult (look at the
> current thread on gbak on firebird-support)
>
>
> > thanks
> You'll thank me if I made sense at all! :)
> Didier
>
> > -Gerhard