X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A4AC7D1B89A for ; Mon, 27 Oct 2003 19:58:23 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 17723-06 for ; Mon, 27 Oct 2003 15:57:52 -0400 (AST) Received: from mck.abak.info.pl (host-213-25-17-172.olsztyn.mm.pl [213.25.17.172]) by svr1.postgresql.org (Postfix) with ESMTP id D9AE1D1B55F for ; Mon, 27 Oct 2003 15:57:46 -0400 (AST) Received: from mail by mck.abak.info.pl with scanned-mks (ABAK.info.pl Secure SMTP) id 1AEDZM-00016Y-00 for ; Mon, 27 Oct 2003 21:02:29 +0100 Received: from net.wmbr.com.pl ([195.116.72.86] helo=panoramix) by mck.abak.info.pl with asmtp (ABAK.info.pl Secure SMTP) id 1AEDZJ-00016S-00; Mon, 27 Oct 2003 21:02:27 +0100 Content-Type: text/plain; charset="utf-8" From: Mariusz Pekala To: pgsql-php@postgresql.org Subject: Re: Saving result to file for download Date: Mon, 27 Oct 2003 20:56:22 +0100 User-Agent: KMail/1.4.3 References: <315833F6-07CB-11D8-B456-0005029FC1A7@myrealbox.com> In-Reply-To: <315833F6-07CB-11D8-B456-0005029FC1A7@myrealbox.com> Cc: Michael Glaesemann MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200310272056.28937.skoot@qi.pl> X-Virus-Scanned: by mks_vir for linux X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/30 X-Sequence-Number: 2391 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello! Michael Glaesemann (nie 26. pa=C5=BAdziernik 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=E2=80=94they can just generate a new one. Why have you decided to store results in a file? Is that file to be really= =20 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=20 (eg: get file here 2) The script "file.php" sets the content type header to text/plain and jus= t=20 outputs the result of a query. I am not sure how to set HTTP header on Your= =20 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=3DISO-8859-2"); // See RFC 2183 [49] (which updates RFC 1806) for details. Content-Disposit= ion=20 is not part of HTTP standard, but is widely used. header("Content-Disposition: attachment; filename=3Danka.txt"); After this you just output your data. That should work. You would then have no troubles with filenames-conflicts,= =20 disk space wasting and so on. However some browsers may ignore the content-disposition header and suggest= =20 the filename 'file.php' when saving. I suppose that's not a big problem... Bye, M.P. - --=20 [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=3D =3D1CVb -----END PGP SIGNATURE-----