六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 51|回复: 0

Perl实现文件下载

[复制链接]

升级  31.33%

25

主题

25

主题

25

主题

秀才

Rank: 2

积分
97
 楼主| 发表于 2013-2-7 15:28:05 | 显示全部楼层 |阅读模式
use CGI ':standard';use CGI::Carp qw(fatalsToBrowser);  my $files_location;  my $ID;  my @fileholder;$files_location = "/data/";$ID = param('file_name');if ($ID eq '') {      print "Content-type: text/html\n\n";      print "You must specify a file to download.";  } else {    if(-e "$files_location/$ID")    {    }    else    {          print header;          print qq{<hmtl><head><title>The file doesn't exist.</title>        </head><body><br/><br/>  <br/><center><h1>The file does not exist.</h1></center></body></html>};          exit;    }    open(DLFILE, "<$files_location/$ID") || Error('open', 'file');      @fileholder = <DLFILE>;      close (DLFILE) || Error ('close', 'file');      #open (LOG, ">>/usr50/home/webdata/public_html/test.log") || Error('open', 'file');    #print LOG "$ID\n";    #close (LOG);    print "Content-Type:application/x-download\n";      print "Content-Disposition:attachment;filename=$ID\n\n";    print @fileholder}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表