pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ljb <ljb220@mindspring.com>
To: pgsql-php@postgresql.org
Subject: Re: blob size after pg_lo_open
Date: Thu, 12 Aug 2004 01:13:21 +0000 (UTC)
Message-ID: <cfeg7h$1lt7$1@news.hub.org> (raw)
References: <OFA9DD8091.F712662A-ON88256EED.0072CAFD-88256EED.00731A65@sybex.com>

TDyson@sybex.com wrote:
> I have to store some files in a database and let users download the files. 
>   I want to pull the file size so I can use the HTTP Content-length 
> header.  I've tried using PHP's fstat to return the size, but I think the 
> object returned by pg_lo_open is not suitable.

No, you can't use fstat() on a large object handle. If you really need the
large object size, you have to open the large object with pg_lo_open(),
seek to the end with pg_lo_seek($loid, 0, PGSQL_SEEK_END), and then get the
position with pg_lo_tell($loid). This will return the number of bytes in
the large object. But if you find yourself doing this a lot, you might be
better off storing the file size (as calculated when uploaded) in another
field in the database record.

> Any ideas?  BTW, I figured this was a pretty common need, but I could not 
> find a complete widget to deal with it.  The best I could come up with was 
> complete apps, mostly image galleries, and a few code snippets.

I've hardly ever bothered with Content-length. There is probably some
advantage to using it but I don't know what it might be.



view thread (3+ messages)  latest in thread

Message-ID: <cfeg7h$1lt7$1@news.hub.org>
Permalink:  ../cfeg7h$1lt7$1@news.hub.org/
Also on:    postgresql.org/message-id/cfeg7h$1lt7$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: ljb220@mindspring.com
  Subject: Re: blob size after pg_lo_open
  In-Reply-To: <cfeg7h$1lt7$1@news.hub.org>
  References: <OFA9DD8091.F712662A-ON88256EED.0072CAFD-88256EED.00731A65@sybex.com> <cfeg7h$1lt7$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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