perl上传多个文件的问题

perl上传多个文件的问题
我上传三个文件,结果只有第一个文件写入了内容,而后面两个却是空文件,大家帮我看看吧 !谢谢!
代码如下:
upload.html
<html>

<body>

<form method="POST" action="/cgi-bin/upload.cgi"
ENCTYPE="multipart/form-data">

File 1:

<input type="file" name="FILE1">

<br>

File 2:

<input type="file" name="FILE2">

<br>

File 3:

<input type="file" name="FILE3">

<br>

<input type="submit" value="Upload!">

</form>

</body>

</html>


upload.cgi
#!/usr/bin/perl

use CGI;

$upfilecount = 1;

$maxuploadcount = 3; #限制上传文件的最大数

$basedir = "/var/www/cgi-bin/"; #上传的文件存放地址

$allowall = "no"; #是否不限制文件后缀上传

@theext =(".zip",".exe",".gif"); #要限制的文件后缀名

print "Content-type: text/html\n\n";

while ($upfilecount <= $maxuploadcount) {
my $req = new CGI;

my $file = $req->param("FILE$upfilecount");

if ($file ne "") {

my $fileName = $file;

$fileName =~ s/^.*(\\|\/)//; #用正则表达式去除无用的路径名,得到文件名

my $newmain = $fileName;

my $filenotgood;

if ($allowall ne "yes") {

$extname = lc(substr($newmain,length($newmain) - 4,4)); #取后缀名

for(my $i = 0; $i < @theext; $i++){ #这段进行后缀名检测

if ($extname eq $theext[$i]){

$filenotgood = "yes";

last;

}

}

}

if ($filenotgood ne "yes") { #这段开始上传

open (OUTFILE, ">$basedir/$fileName");
#print "$fileName\n";

binmode(OUTFILE);
#务必全用二进制方式,这样就可以放心上传二进制文件了。而且文本文件也不会受干扰
while (read($file, $buffer, 1024)) {

print OUTFILE $buffer;

}

close (OUTFILE);
print "$fileName";
system("bl2seq -i $fileName -j /home/zrz/Desktop/$fileName -p blastn -o junk");
#system("rm $fileName");
$message.=$file . " 已成功上传!<br>\n";

}

else{

$message.=$file . " 文件后缀不符合要求,上传失败!<br>\n";

}

}
$upfilecount++;
}

print $message; #最后输出上传信息