CGI perl:下载脚本不起作用

时间:2013-01-14 10:12:16

标签: perl file cgi downloading

print $page->p("Hello All, Downloading file");
my @contents= $ssh->file_content("$dir/$file", 1);
download(@contents, $file);
...
...
...
sub download {
    use strict;
    my @content = shift;
    my $filename = shift;
    print "Content-Type:application/x-download\n";
    print "Content-Disposition: attachment;filename=$file\n\n";
    print @content;
    return 1;
}

但它不是下载它,而是在屏幕上打印文件的内容。 请告诉我我哪里错了?

1 个答案:

答案 0 :(得分:0)

尝试保持标头符合HTTP标准:

print "Content-Type: application/x-download\r\n";
print "Content-Disposition: attachment;filename=$file\r\n\r\n";
print @content;