[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-isp
Subject:    Re: OT: cgi should produce a file with a different name
From:       Alexander Leidinger <Alexander () Leidinger ! net>
Date:       2000-06-30 12:53:17
[Download RAW message or body]

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic