From owner-freebsd-isp Fri Jun 30 9:31:34 2000 Delivered-To: freebsd-isp@freebsd.org Received: from mout0.freenet.de (mout0.freenet.de [194.97.50.131]) by hub.freebsd.org (Postfix) with ESMTP id E8DAE37B738 for ; Fri, 30 Jun 2000 09:31:25 -0700 (PDT) (envelope-from netchild@leidinger.net) Received: from [194.97.50.138] (helo=mx0.freenet.de) by mout0.freenet.de with esmtp (Exim 3.14 #3) id 1383hH-0004gZ-00; Fri, 30 Jun 2000 18:31:19 +0200 Received: from [213.6.46.113] (helo=Magelan.Leidinger.net) by mx0.freenet.de with esmtp (Exim 3.14 #3) id 1383hH-0000eg-00; Fri, 30 Jun 2000 18:31:19 +0200 Received: from Leidinger.net (netchild@localhost [127.0.0.1]) by Magelan.Leidinger.net (8.9.3/8.9.3) with ESMTP id OAA01257; Fri, 30 Jun 2000 14:53:19 +0200 (CEST) (envelope-from netchild@Leidinger.net) Message-Id: <200006301253.OAA01257@Magelan.Leidinger.net> Date: Fri, 30 Jun 2000 14:53:17 +0200 (CEST) From: Alexander Leidinger Subject: Re: OT: cgi should produce a file with a different name To: leifn@neland.dk Cc: freebsd-isp@FreeBSD.ORG In-Reply-To: MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii Sender: owner-freebsd-isp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On 30 Jun, Leif Neland wrote: > This script generates a datafile, which should be downloaded. > So the type should probably be application/data. > > But how do I suggest to the browser, that the name should be > "data123.dat", where 123 is varying, depending on the input, and not > "script.cgi" > > I'm using perl and CGI.pm I use something like this with PHP (just ask if you don't know the semantic of a used function): ---snip--- $MD5 = 0; $MD5SUM = 0; $AWK = 0; if(file_exists("/usr/local/bin/md5")) { $md5 = "/usr/local/bin/md5"; $MD5 = 1; } elseif(file_exists("/sbin/md5")) { $md5 = "/sbin/md5"; $MD5 = 1; } elseif(file_exists("/usr/gnu/bin/md5sum")) { $md5sum = "/usr/gnu/bin/md5sum"; $MD5SUM = 1; } if(file_exists("/usr/bin/awk")) { $awk = "/usr/bin/awk"; $AWK = 1; } if($MD5SUM && $AWK) $prog = $md5sum." ".$file." | ".$awk." '\$1 \$2 {print \$1}'"; elseif($MD5 && $AWK) $prog = $md5." ".$file." | ".$awk." '\$1 \$2 {print \$2}'"; $size = filesize($file); header("HTTP/1.1 200"); header("Content-Lenght: $size"); header("Cache-Control: no-cache"); header("Content-Disposition: attachment; filename=\"$what\""); if(($MD5 || $MD5SUM) && $AWK) header("Content-MD5: ".base64_encode(exec($prog))); if(!strcmp( $F, "zip")) header("Content-Type: application/x-zip-compressed"); else header("Content-Type: application/octet-stream"); @readfile($file) ---snip--- Some user agents didn't like this (MSIE 4, Lynx (at least old versions)), they did not (offer to) save the file. Opera 3.? offers to save, but didn't use the supplied filename. Bye, Alexander. -- Give a man a fish and you feed him for a day; teach him to use the Net and he won't bother you for weeks. http://www.Leidinger.net Alexander+Home @ Leidinger.net GPG fingerprint = 7423 F3E6 3A7E B334 A9CC B10A 1F5F 130A A638 6E7E To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-isp" in the body of the message