Date: Fri, 30 Jun 2000 14:53:17 +0200 (CEST) From: Alexander Leidinger <Alexander@Leidinger.net> To: leifn@neland.dk Cc: freebsd-isp@FreeBSD.ORG Subject: Re: OT: cgi should produce a file with a different name Message-ID: <200006301253.OAA01257@Magelan.Leidinger.net> In-Reply-To: <Pine.BSF.4.05.10006301317490.96965-100000@arnold.neland.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006301253.OAA01257>