Hi!
I used POST_MAX,and it's succeed,but the browser has not any result,why?
-------------------------------------------------------------
#!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/^.*(\\|\/)//;  #用正则表达式去除无用的路径名,得到文件名
                   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&nb! sp; .  "  文件后缀不符合要求,上传失败!<br>\n";
                   }
                  
                 }else{
                         $message.=$file  .  "  文件大小不符合要求,上传失败!<br>\n";
                 }
         }
           $upfilecount++;
          
}
print status=>cgi_error();
print  $message;!   #最后输出上传信息
-----------------------------------------------------------------

$Bill Luebkert <[EMAIL PROTECTED]> wrote:
Tony Cheung wrote:

> If I want to use $CGI::POST_MAX ,how to wirte in my program,thanks.

Try reading the docs :

=item B<$CGI::POST_MAX>

If set to a non-negative integer, this variable puts a ceiling
on the size of POSTings, in bytes. If CGI.pm detects a POST
that is greater than the ceiling, it will immediately exit with an error
message. This value will affect both ordinary POSTs and
multipart POSTs, meaning that it limits the maximum size of file
uploads as well. You should set this to a reasonably high
value, such as 1 megabyte.

=item B<$CGI::DISABLE_UPLOADS>

If set to a non-zero value, this will disable file uploads
completely. Other fill-out form values will work as usual.

=back

You can use these variables in either of two ways.

=over 4

=item B<1. On a script-by-s! cript basis>

Set the variable at the top of the script, right after the "use" statement:

use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
$CGI::POST_MAX=1024 * 100; # max 100K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads

=item B<2. Globally for all scripts>

Open up CGI.pm, find the definitions for $POST_MAX and
$DISABLE_UPLOADS, and set them to the desired values. You'll
find them towards the top of the file in a subroutine named
initialize_globals().

=back

An attempt to send a POST larger than $POST_MAX bytes will cause
I to return an empty CGI parameter list. You can test for
this event by checking I, either after you create the CGI
object or, if you are using the function-oriented interface, call
for the first time. If the POST was intercepted, then
cgi_error() will return the message "413 POST too large".

This error message is actually defined by t! he HTTP protocol, and is
designed to be returned to the browser as the CGI script's status
code. For example:

$uploaded_file = param('upload');
if (!$uploaded_file && cgi_error()) {
print header(-status=>cgi_error());
exit 0;
}

However it isn't clear that any browser currently knows what to do
with this status code. It might be better just to create an
HTML page that warns the user of the problem.



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



Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to