0

我正在尝试将文件的内容(原始内容)发送到浏览器。但是文件作为附件交付,即使标题中没有附件。谁能建议我如何使用 perl 在浏览器上显示原始数据?

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use File::Copy qw( copy );
use File::Spec::Functions qw( catfile );
use POSIX qw(strftime);
use Time::Local;
use HTTP::Status qw(:constants :is status_message);
use Digest::MD5 qw(md5 md5_hex md5_base64);
use File::Basename;
use URI;



my $extfile = '/home/suresh/clientrequest.txt';
open(FH, ">>$extfile") or die "Cannot open file";
my $query = CGI->new;
my $stcode = status_message(206);
my $uri =$ENV{'REQUEST_URI'};
my $rdate =strftime("%a, %d %b %Y %H:%M:%S %Z", localtime());
print FH "Client request: ", $ENV{'REQUEST_URI'}, "\n";
my $dir  = '/srv/samba/Assets';
#my $dir  = '/home/suresh/Assets';
my $nffFile = fileparse ("$uri", qr/\.[^.]*/);
my $fullFname = $nffFile . ".nff";
my $path = catfile($dir, $fullFname);
my $filesize = -s $path;
print FH "Size of the file: ", $filesize, "\n";

#Search requested asset files
opendir(DIR, $dir);
my @files = readdir(DIR);
if (grep($_=~/$fullFname/,@files)){
print FH "Found the requested NFF file: ", $fullFname, "\n"; 
open my $fh, '<:raw', $path;
print "$ENV{SERVER_PROTOCOL} 206 $stcode";
print $query->header(
    -'Accept-Range'=>'bytes',
    -'Date'=> $rdate,
    -'Content-Range'=>'0-188/$filesize',
    -'Content-Length'=>$filesize,
    -'Content-Type'=>'application/octet-stream',
    -'Connection'=>'Keep-Alive',
    -'Media-Type'=>'application/octet-stream',
    );
binmode STDOUT, ':raw';
    copy $fh => \*STDOUT;
    close $fh
        or die "Cannot close '$path': $!";

}else {
    print $query->header('text/plain', '404 File not Found!');
    print FH "Requested NFF file: ", $fullFname, " not found!!\n\n";
    }
closedir(DIR);
4

1 回答 1

0

解决了..这是一个简单的更改,我需要将内容类型更改为 text/html 以存档。

于 2013-10-04T20:47:37.273 回答