我無法在cgi perl下載該文件。相反,我得到的內容打印在網頁上。這是我試過的。在cgi perl腳本中下載文件
代碼:
use CGI qw /:standard /;
use CGI;
print "Content-type:text/html\n\n";
my $files_location;
my $ID;
my @fileholder;
$directorypath = "/var/www/cgi-bin/";
$files_location = $directorypath;
$ID = 'file.txt';
#$ID = param('ID');
if ($ID eq '') {
print "You must specify a file to download.";
} else {
open(DLFILE, "<$files_location/$ID") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
#these are the html codes that forces the browser to open for download
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder;
}
我得到這個:
Content-Type:application/x-download Content-Disposition:attachment;filename=file.txt ih how are u iam hre
file.txt的
IH如何爲U IAM HRE
不過我得到的same.No變化 – Nagaraju
設我更具體。請在腳本中註釋掉或完全刪除第4行。仍然是相同的結果? –
我得到內部服務器錯誤 – Nagaraju