SPUG: HTTP Headers
tleffler at u.washington.edu
Tue Dec 11 12:35:21 CST 2001
First off, I'm going to ignore that you're storing entire binary docs in
your DB, rather than letting your web server serve them up via the
We came up with one possible solution, which assumes you're using
Apache. Create a link URL such as:
Since the real filename is in the URL, your browser will use it in the
"Save" dialog box.
The /download directory has only a .htaccess file with these contents:
ErrorDocument 404 /somepath/nph-download.cgi
Since /download/CMS_SOP.doc doesn't actually exist, the nph-download.cgi
script gets called instead. That script then finds the document via
your DB thanks to the docid you passed it (we just store the private
path to the doc, rather than the doc itself), prints the appropriate
HTTP headers and Content-type, and streams the file contents to the browser.
The reason you use an nph- script is to override the server headers,
which will show a 404 "File not found" status. You'll want to start by
printing something like:
print "HTTP/1.1 200 OK\n",
Then print an error page is something fails, or your Content-type and
contents if everything succeeds.
As an aside, you might think about using adequately random docid's, or
perhaps encrypting them so that I can't download all your documents via
iteration. That is, if doc access is an issue.
Trevor Leffler, Software Developer
PETTT / Ed-Tech Development Group
University of Washington
(206) 616-3406 / OUGL 230, Box 353080
Parr, Ryan wrote:
> I'm currently moving the intranet site I work on to be completely database
> based. However, I'm running into a snag with delivering documents to the
> user. Rather, delivering documents other than HTML to the user.
> If I have my CGI load a word doc that's stored in the database, and send it
> to the user with the appropriate mime type, the browser can handle it
> appropriately. Unfortunately though, I have no way to specify a filename for
> the content. So instead of receiving an Open/Save dialog for CMS_SOP.doc
> they receive an Open/Save dialog for /cgi-bin/loadpage.cgi?id=334, or the
> browser loads the word doc with the filename /cgi-bin/loadpage.cgi?id=334.
> I haven't been able to find any standard HTTP headers that deal with this
> scenario, nor any IE specific extension headers. I'm in a controlled
> environment so everyone has IE 4+. This approach to document delivery seems
> natural enough to me that I'm sure a thousand developers before me have
> attempted it, certainly some with success. Have any of you?
> -- Ryan Parr
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
More information about the spug-list