我无法在手机设备上下载文件,但我可以在电脑上下载 我试过这两个代码
代码1:
my $filepath = "/var/www/html/uploads";
my $filesize = -s "$filepath";
$|++;
open(my $in_fh,"$filepath") || die "cantopensource";
my $buf;
print"Content-Type: application/force-download\n";
print qq{Content-Disposition: attachment; filename="$filename"\n};
print"Content-length: $filesize\n\n";
while( read($in_fh,$buf,4096) )
{
print $buf;
select(undef, undef, undef,0.006);
}
exit;
代码2:
my $filepath = "/var/www/html/uploads";
print ("Content-Type:application/x-download\n");
print "Content-Disposition: attachment; filename=$filename\n\n";
open FILE, "< $filepath" or die "can't open : $!";
binmode FILE;
local $/ = \10240;
while (<FILE>){
print $_;
}
close FILE;
使用成功下载的PC文件时,但使用手机设备时,请下载.htm文件
我认为问题出在Content-Type
或Content-Disposition