有关文件下载的问题-如何给默认下载的文件加个的扩展名(附下载原程序)

fxjzh 2003-01-10 09:03:01
或者保持名字不变也是可以的,谢谢各位
#!/usr/bin/perl

$imagefile="/var/image/ima.gif";
$f_size=(-s $imagefile);
print "Content-type:application/octet-stream\n";
print "Content-Disposition:attachment;filename=$imagefile\n";
print "Content-Length:$f_size\n\n";
open(IMAGE,"<$imagefile") || die "don't open the file $imagefile\n";
while (read(IMAGE,$buffer,8192))
{print $buffer;
}
close IMAGE;
...全文
109 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
AllCHN 2003-01-22
  • 打赏
  • 举报
回复
点击右上的管理
fxjzh 2003-01-22
  • 打赏
  • 举报
回复
结帖!!!!!!!!!
fxjzh 2003-01-22
  • 打赏
  • 举报
回复
结帖
fxjzh 2003-01-21
  • 打赏
  • 举报
回复
AllCHN(大中国) :谢谢!
fxjzh 2003-01-21
  • 打赏
  • 举报
回复
我想结帖了,如何做啊?
AllCHN 2003-01-20
  • 打赏
  • 举报
回复
因为有模式的问题,对二进制流数据,完整合格的程序如下,否则下载的二进制文件和实际的文件有差别:

#!/usr/bin/perl
$downloadfile="/var/image/ima.gif";
$dlname = $downloadfile;
$dlname =~ s/\\/\//g; # 避免 Windows 格式路径带来的问题
if ($dlname =~ /\/([^\/]+)$/) { # 取得文件名:指定文件名时不能有路径)
$dlname = $1;
}
$f_size=(-s $downloadfile);
print "Content-type: application/octet-stream\n";
print "Content-Disposition: inline; filename=\"$dlname\"\n\n";
#print "Content-Length: $f_size\n\n";
open(FILE,"<$downloadfile") || die "don't open the file $downloadfile\n";
binmode(FILE);
binmode(STDOUT);
while (read(FILE,$buffer,8192)) {
print $buffer;
}
close FILE;
exit 0;
AllCHN 2003-01-20
  • 打赏
  • 举报
回复
#!/usr/bin/perl

$imagefile="/var/image/ima.gif";
$dlname = $imagefile;
$dlname =~ s/\\/\//g; # 避免 Windows 格式路径带来的问题
if ($dlname =~ /\/([^\/]+)$/) { # 取得文件名:指定文件名时不能有路径)
$dlname = $1;
}
$f_size=(-s $imagefile);
print "Content-type:application/octet-stream\n";
print "Content-Disposition:attachment;filename=$dlname\n";
print "Content-Length:$f_size\n\n";
open(IMAGE,"<$imagefile") || die "don't open the file $imagefile\n";
while (read(IMAGE,$buffer,8192))
{print $buffer;
}
close IMAGE;

2,203

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧