#!/usr/bin/perl
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $files_location;
my $ID;
my @fileholder;
$files_location = "C:\Users\user\Documents\hello\icon.png";
open(DLFILE, "<$files_location") ;
@fileholder = <DLFILE>;
close (DLFILE) ;
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder;
私はこのスクリプトを実行し、代わりにそれが何のコンテンツも内側とdownload.pl
(上記のスクリプトの名前を)返しませんicon.png
ファイルを返します。どうした?私のイメージダウンロードのPerlで書かれたCGIスクリプトが動作しないのはなぜですか?
私は現在使用中です。
#!C:\Perl64\bin\perl.exe -w
use CGI qw(:standard);
use File::Copy qw(copy);
use File::Spec::Functions qw(catfile);
use constant IMG_DIR => catfile(qw( D:\ ));
serve_logo(IMG_DIR);
sub serve_logo {
my ($dir) = @_;
my $cgi = CGI->new;
my $file = "icon.png";
#print $file;
defined ($file) or die "Invalid image name in CGI request\n";
send_file($cgi, $dir, $file);
return;
}
sub send_file
{
my ($cgi, $dir, $file) = @_;
my $path = catfile($dir, $file);
open my $fh, '<:raw', $path or die "Cannot open '$path': $!";
print $cgi->header( -type => 'application/octet-stream', -attachment => $file, );
binmode STDOUT, ':raw';
copy $fh => \*STDOUT, 8_192;
close $fh or die "Cannot close '$path': $!";
return;
}
+1 :: Nice答え。 –
http://www.sitepoint.com/file-download-script-perl/私はソースを入手した場所です。彼にとってはうまくいっているようだ。だから私はどのように堅牢な方法でこのバイナリファイルをダウンロードします。チュートリアル。 – user1092042
仕事の定義については、正しいかもしれません。しかし、それは***働く***の私の定義ではない、明らかに、それは動作しません、またはあなたはこの質問を投稿していないでしょうか?私はここに何かを逃していますかその記事とそこに含まれているアドバイスは駄目です。 –