pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Link to a file stored in a database (PostgreSQL)
2+ messages / 2 participants
[nested] [flat]

* Link to a file stored in a database (PostgreSQL)
@ 2002-05-27 10:30 re ert <matlab21@yahoo.es>
  2002-05-27 10:54 ` Re: Link to a file stored in a database (PostgreSQL) Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 1 reply; 2+ messages in thread

From: re ert @ 2002-05-27 10:30 UTC (permalink / raw)
  To: pgsql-php

Hi:

I want store files in PostgreSQL and retrieve it
without put files in a temp directory.

For example, PHP can create image files with:

header("Content-type: image/gif");

and call this file image.php ... each time somebody
calls this file, PHP must create the image.

I need do the same but with a file stored in a
database.
For example, I want store a PDF file in a database and
could get it with a link.

Thanks a lot.

Xevi.


_______________________________________________________________
Copa del Mundo de la FIFA 2002
Disfruta en vĂ­deo de los mejores momentos desde tu ordenador.
http://fifaworldcup.yahoo.com/fc/es/



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Link to a file stored in a database (PostgreSQL)
  2002-05-27 10:30 Link to a file stored in a database (PostgreSQL) re ert <matlab21@yahoo.es>
@ 2002-05-27 10:54 ` Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 0 replies; 2+ messages in thread

From: Andrew McMillan @ 2002-05-27 10:54 UTC (permalink / raw)
  To: re ert <matlab21@yahoo.es>; +Cc: pgsql-php

On Mon, 2002-05-27 at 22:30, re ert wrote:
> Hi:
> 
> I want store files in PostgreSQL and retrieve it
> without put files in a temp directory.
> 
> For example, PHP can create image files with:
> 
> header("Content-type: image/gif");
> 
> and call this file image.php ... each time somebody
> calls this file, PHP must create the image.
> 
> I need do the same but with a file stored in a
> database.
> For example, I want store a PDF file in a database and
> could get it with a link.

I have tried to do this with mixed success, storing the binary files as
a 'large object' within PostgreSQL.

The basic function, as you surmise, is to send the appropriate headers,
get the data out of the database and pump it out to the user.  Here's a
fragment from my server:

  Header("Content-type: $content_type");
  error_log("LO ID is >>$loid<<", 0);
  $rid = pg_exec( $img_db, "BEGIN;" );
  $fd = pg_loopen( $img_db, intval($loid), "r" );
  $fstats = fstat($fd);
  error_log("Img bytes should be: " . $fstats[7], 0);
  Header("Content-length: $fstats[7]");
  pg_loreadall( $fd );
  pg_loclose($fd);
  $rid = pg_exec( $img_db, "COMMIT;");

The biggest gotcha seemed to be that all LO access needs to occur within
a transaction.

Cheers,
					Andrew.
-- 
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/        PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201    MOB: +64(21)635-694    OFFICE: +64(4)499-2267
       Are you enrolled at http://schoolreunions.co.nz/ yet?




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-05-27 10:54 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-27 10:30 Link to a file stored in a database (PostgreSQL) re ert <matlab21@yahoo.es>
2002-05-27 10:54 ` Andrew McMillan <andrew@catalyst.net.nz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox