Tony Cheung wrote:

> Hi!
> I used POST_MAX,and it's succeed,but the browser has not any result,why?

Who knows.  1) I'm not going to play with a script that doesn't have a use strict
to start it off.  2) You should remove the code you added to test the file size
now that CGI is handling it.  I'm sure there are other errors in the script that
will show up with use strict in force.

> -------------------------------------------------------------
> #!c:\perl\bin\perl
> #如果用CGI方式来行动这个文件,请把下段路径改成你的机器配置
> use  CGI; 
> $upfilecount  =  1;
> $maxuploadcount  =  2;  #限制上传文件的最大数
> $basedir  =  "c:/English";  #上传的文件存放地址
> $allowall  =  "no";  #是否不限制文件后缀上传
> @theext  =(".zip",".exe",".gif",".rm",".doc",".xls",".mp3"); 
> #要限制的文件后缀名
> $filesize = 220842;  #限制文件大小在216K
> 
> $CGI::POST_MAX=$filesize;
>  
> 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;
>                 my $file_size = -s $file;
>                 print $file_size."\n";
>         if ($file_size < $filesize) {
>                
>                    $fileName  =~  s/^.*(\\|\/)// <file://\\|\/)//>; 
> #用正则表达式去除无用的路径名,得到文件名
>                    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");
>                            binmode(OUTFILE); 
> #务必全用二进制方式,这样就可以放心上传二进制文件了。而且文本文件也不会受干扰
>                            while  (my  $bytesread  =  read($file,  my 
> $buffer,  1024))  { 
>                                    print  OUTFILE  $buffer;
>                            }
>                            close  (OUTFILE);
>                            $message.=$file  .  "  已成功上传!<br>\n";
>                    }
>                    else{
>                            $message.=$file  .  " 
> 文件后缀不符合要求,上传失败!<br>\n";
>                    }
>                   
>                  }else{
>                          $message.=$file  .  " 
> 文件大小不符合要求,上传失败!<br>\n";
>                  }
>          }
>            $upfilecount++;
>           
> }
> print status=>cgi_error();
> print  $message;  #最后输出上传信息


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to