- 论坛徽章:
- 6
|
本帖最后由 stanley_tam 于 2014-04-21 14:25 编辑
虽然CGI很out了。但是有需求,要用一下。。。{:3_199:}
我用下面的方式生成下载文件test.csv的http response,为啥在下载后的文件test.csv里的第一行是空行(事实上并没有空行)?- use strict;
- use warnings;
- use CGI qw/:standard/;
- my $q = CGI->new;
- say $q->header(
- -'Content-Type' => qq{application/octet-stream;name="test.csv"},
- -'Content-Disposition' => qq{attachment;filename="test.csv"},
- );
- my $download_fh;open $download_fh, '<', 'test.csv';
- my $buffer;
- binmode $download_fh;
- while( read($download_fh, $buffer, 100) ){
- print $buffer ;
- }
- close $download_fh;
- __END__
复制代码 |
|