Re: Saving result to file for download

From: Mariusz Pekala <skoot(at)qi(dot)pl>
To: pgsql-php(at)postgresql(dot)org
Cc: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Subject: Re: Saving result to file for download
Date: 2003-10-27 19:56:22
Message-ID: 200310272056.28937.skoot@qi.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello!

Michael Glaesemann (nie 26. październik 2003 16:43):
> Hi all!
>
> I made a PHP script that formats and saves the output of a query to a
> file and provides a link to the file for download. I've never done this
> before and would appreciate any feedback. Here are things I'd like to
> improve or am concerned about.
> [...]
> 1. Right now the file is permanently saved in a directory [...]
> [...]
> I'd rather it be a temporary file so I wouldn't have to worry
> about clearing out the files if a lot of people generate results files.
> I'm not concerned that people won't be able to come back to the results
> file at a later date—they can just generate a new one.

Why have you decided to store results in a file? Is that file to be really
big? or takes long to prepare?

Maybe generating the file 'on the fly' would be easier:

1) Provide a link to a script that generates the file
(eg: <a href="file.php?type=whatever">get file here</a>

2) The script "file.php" sets the content type header to text/plain and just
outputs the result of a query. I am not sure how to set HTTP header on Your
webserver (with apache there is a PHP function header(string) )

You may find two HTTP headers interesting (examples from my script):

header("Content-type: text/plain; charset=ISO-8859-2");
// See RFC 2183 [49] (which updates RFC 1806) for details. Content-Disposition
is not part of HTTP standard, but is widely used.
header("Content-Disposition: attachment; filename=anka.txt");

After this you just output your data.
That should work. You would then have no troubles with filenames-conflicts,
disk space wasting and so on.
However some browsers may ignore the content-disposition header and suggest
the filename 'file.php' when saving. I suppose that's not a big problem...

Bye,
M.P.

- --
[http://skoot.qi.pl for GPG keys]
"A computer programmer is someone who, when told to "Go to Hell", sees
the "Go to", rather than the destination, as harmful."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE/nXhmvkWo15WV1rkRAjJ+AKCTZt4M6iu63kFRBgxeE7kjAvuZZgCfZI3b
QlXY7b+UpgvSqsojFoLY1UI=
=1CVb
-----END PGP SIGNATURE-----

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Michael Glaesemann 2003-10-28 00:01:55 Re: Saving result to file for download
Previous Message Adam Witney 2003-10-27 08:59:18 Re: array fields in the database and their handling with php4