通过Perl脚本阅读时,PDF在浏览器中不显示
问题描述:
我试图将文件读入我的perl脚本,然后根据文件类型适当设置标题. PDF未显示,我在想我的服务器人员已将此东西锁定.我可能对此脚本做错了什么?
I'm trying to read in a file to my perl script and then set the headers appropriately based on the filetype. PDFs are not displaying and i'm thinking that my server guy has this thing locked down. Is there anything that I may be doing wrong with this script?
my $q = CGI->new; #instantiate the CGI object
my $filename = $q->param('file'); # get the file param from the query string
my $text = read_file($filename); # read in the file
my($name, $path, $suffix) = fileparse($filename, qr/\..*/);
if($suffix eq ".pdf") {
print $q->header('Content-type: application/pdf');
} else {
print $q->header('text/html');
}
答
$ perl -MCGI -E'my $q = CGI->new; print $q->header("Content-type: application/pdf");'
Content-Type: Content-type: application/pdf; charset=ISO-8859-1
您正在生成无效的标题.将'application/pdf'
或-type => 'application/pdf'
或'Content-Type' => 'application/pdf'
用作 header
方法的参数.
You are generating an invalid header. Use either 'application/pdf'
or -type => 'application/pdf'
or 'Content-Type' => 'application/pdf'
as arguments to the header
method.