Re: How to obtain filesize?

2004-11-05 Thread Tony Cheung
Please help me test this program,thanks!
Thank you very much!
---
upload.html
---
http://localhost/cgi-bin/upload.pl"  ENCTYPE="multipart/form-data">File  1:  File  2:  
===
--
upload.pl
--
#!c:\perl\bin\perl
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  .  "  upload ok!\n";   }   else{   $message.=$file&nbs!
 p;
 .  "  file postfix error!\n";   }    }else{ $message.=$file  .  "  file too large!\n";  } }   $upfilecount++;   }print status=>cgi_error();print  $message;  
=
I use apache1.2.36 in my pc.$Bill Luebkert <[EMAIL PROTECTED]> wrote:
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 strictto start it off. 2) You should remove the code you added to test the file sizenow that CGI is handling it. I'm sure there are other errors in the script thatwill 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"); > #要限制的文件后缀名> $files!
 ize =
 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 . " 已成功上传!\n";> }> else{> $message.=$file . " > 文件后缀不符合要求,上传失败!\n";> }> > }else{> $message.=$file . " > 文件大小不符合要求,上传失败!\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/-/-' /___/_<_Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: How to obtain filesize?

2004-11-05 Thread $Bill Luebkert
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/^.*(\\|\/)// ; 
> #ÓÃÕýÔò±í´ïʽȥ³ýÎÞÓõÄ·¾¶Ãû£¬µÃµ½ÎļþÃû
>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  .  "  Òѳɹ¦ÉÏ´«!\n";
>}
>else{
>$message.=$file  .  " 
> Îļþºó׺²»·ûºÏÒªÇó£¬ÉÏ´«Ê§°Ü!\n";
>}
>   
>  }else{
>  $message.=$file  .  " 
> Îļþ´óС²»·ûºÏÒªÇó£¬ÉÏ´«Ê§°Ü!\n";
>  }
>  }
>$upfilecount++;
>   
> }
> print status=>cgi_error();
> print  $message;  #×îºóÊä³öÉÏ´«ÐÅÏ¢


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[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


Re: How to obtain filesize?

2004-11-05 Thread Tony Cheung
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  .  "  已成功上传!\n";   }   else{   $message.=$file&nb!
 sp;
 .  "  文件后缀不符合要求,上传失败!\n";   }    }else{ $message.=$file  .  "  文件大小不符合要求,上传失败!\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 ceilingon the size of POSTings, in bytes. If CGI.pm detects a POSTthat is greater than the ceiling, it will immediately exit with an errormessage. This value will affect both ordinary POSTs andmultipart POSTs, meaning that it limits the maximum size of fileuploads as well. You should set this to a reasonably highvalue, such as 1 megabyte.=item B<$CGI::DISABLE_UPLOADS>If set to a non-zero value, this will disable file uploadscompletely. Other fill-out form values will work as usual.=backYou 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'llfind them towards the top of the file in a subroutine namedinitialize_globals().=backAn attempt to send a POST larger than $POST_MAX bytes will causeI to return an empty CGI parameter list. You can test forthis event by checking I, either after you create the CGIobject or, if you are using the function-oriented interface, callfor the first time. If the POST was intercepted, thencgi_error() will return the message "413 POST too large".This error message is actually defined by t!
 he HTTP
 protocol, and isdesigned to be returned to the browser as the CGI script's statuscode. 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 dowith this status code. It might be better just to create anHTML 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


Re: How to obtain filesize?

2004-11-05 Thread $Bill Luebkert
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-script 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 the 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 LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[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


Re: How to obtain filesize?

2004-11-05 Thread Tony Cheung
If I want to use $CGI::POST_MAX ,how to wirte in my program,thanks.$Bill Luebkert <[EMAIL PROTECTED]> wrote:
Tony Cheung wrote:> Thanks for your help.> I got a program yesterday,and add in it,but program is not word!> #!e:\perl\bin\perl> #如果用CGI方式来行动这个文件,请把下段路径改成你的机器配置> use CGI; > $upfilecount = 1;> $maxuploadcount = 2; #限制上传文件的最大数> $basedir = "e:/English"; #上传的文件存放地址> $allowall = "no"; #是否不限制文件后缀上传> @theext =(".zip",".exe",".gif",".rm",".doc",".xls"); #要限制的文件后缀名> $filesize = 220842; #限制文件大小在216K> 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;You can't check the file size until it's been uploaded. I thinkCGI would have stored the fi!
 le in a
 temporary file at this pointin time and you can use :my $tmpfile = $cgi->tmpFileName($file);my $file_size = -s $tmpfile;CGI can be configured to reject files greater than a given size :$CGI::POST_MAX = $filesize; # prior to the while loop> 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") { #这段开始上传You may be able to just move the temp file rather than copying
 it.> open (OUTFILE, ">$basedir/$fileName");> binmode(OUTFILE); > #务必全用二进制方式,这样就可以放心上传二进制文件了。而且文本文件也不会受干扰> while (my $bytesread = read($file, my > $buffer, 1024)) { > print OUTFILE! $buffer;> }> close (OUTFILE);> $message.=$file . " 已成功上传!\n";> }> else{> $message.=$file&nb! sp; . " > 文件后缀不符合要求,上传失败!\n";> }> > }else{> $message.=$file . " > 文件后缀不符合要求,上传失败!\n";> }> }> $upfilecount++;> > }> print $message; #最后输出上传信息 > > > */Beckett Richard-qswi266 <[EMAIL PROTECTED]>/* wrote:> > All you need to get the file size is -s.> > I.e. $file_size = -s $file> > Save the following script as size.pl, and run like this:> > perl size.pl
 size.pl> > use strict;> use warnings;> my $file = $ARGV[0];> my $file_size = -s $file;> print "$file is $file_size bytes\n";> > > -Original Message-> From: [EMAIL PROTECTED]> [mailto:[EMAIL PROTECTED] On Behalf> Of Tony Cheung> Sent: 03 November 2004 06:54> To: perl-win32-users> Subject: How to obtain filesize?> > > I have a perl program about update file from pc to mysql,but I want> to limit filesize,how to obtain filesize and file type?-- ,-/- __ _ _ $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


Re: How to obtain filesize?

2004-11-04 Thread $Bill Luebkert
Tony Cheung wrote:

> Thanks for your help.
> I got a program yesterday,and add in it,but program is not word!
> #!e:\perl\bin\perl
> #Èç¹ûÓÃCGI·½Ê½À´Ðж¯Õâ¸öÎļþ£¬Çë°Ñ϶η¾¶¸Ä³ÉÄãµÄ»úÆ÷ÅäÖÃ
> use  CGI; 
> $upfilecount  =  1;
> $maxuploadcount  =  2;  #ÏÞÖÆÉÏ´«ÎļþµÄ×î´óÊý
> $basedir  =  "e:/English";  #ÉÏ´«µÄÎļþ´æ·ÅµØÖ·
> $allowall  =  "no";  #ÊÇ·ñ²»ÏÞÖÆÎļþºó׺ÉÏ´«
> @theext  =(".zip",".exe",".gif",".rm",".doc",".xls");  #ÒªÏÞÖƵÄÎļþºó׺Ãû
> $filesize = 220842;  #ÏÞÖÆÎļþ´óСÔÚ216K
> 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;

You can't check the file size until it's been uploaded.  I think
CGI would have stored the file in a temporary file at this point
in time and you can use :

my $tmpfile = $cgi->tmpFileName($file);
my $file_size = -s $tmpfile;

CGI can be configured to reject files greater than a given size :

$CGI::POST_MAX = $filesize; # prior to the while loop

> 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")  {  #Õâ¶Î¿ªÊ¼ÉÏ´«

You may be able to just move the temp file rather than copying it.

>open  (OUTFILE,  ">$basedir/$fileName");
>binmode(OUTFILE); 
> #Îñ±ØÈ«Óöþ½øÖÆ·½Ê½£¬ÕâÑù¾Í¿ÉÒÔ·ÅÐÄÉÏ´«¶þ½øÖÆÎļþÁË¡£¶øÇÒÎı¾ÎļþÒ²²»»áÊܸÉÈÅ
>while  (my  $bytesread  =  read($file,  my 
> $buffer,  1024))  { 
>print  OUTFILE!   $buffer;
>}
>close  (OUTFILE);
>$message.=$file  .  "  Òѳɹ¦ÉÏ´«!\n";
>}
>else{
>$message.=$file&nb! sp; .  " 
> Îļþºó׺²»·ûºÏÒªÇó£¬ÉÏ´«Ê§°Ü!\n";
>}
>
>  }else{
>  $message.=$file  .  " 
> Îļþºó׺²»·ûºÏÒªÇó£¬ÉÏ´«Ê§°Ü!\n";
>  }
>  }
>$upfilecount++;
>
> }
> print  $message;  #×îºóÊä³öÉÏ´«ÐÅÏ¢ 
> 
> 
> */Beckett Richard-qswi266 <[EMAIL PROTECTED]>/* wrote:
> 
> All you need to get the file size is -s.
> 
> I.e. $file_size = -s $file
> 
> Save the following script as size.pl, and run like this:
> 
> perl size.pl size.pl
> 
> use strict;
> use warnings;
> my $file = $ARGV[0];
> my $file_size = -s $file;
> print "$file is $file_size bytes\n";
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Tony Cheung
> Sent: 03 November 2004 06:54
> To: perl-win32-users
> Subject: How to obtain filesize?
> 
> 
> I have a perl program about update file from pc to mysql,but I want
> to limit filesize,how to obtain filesize and file type?


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[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


RE: How to obtain filesize?

2004-11-04 Thread Tony Cheung
Thanks for your help.
I got a program yesterday,and add in it,but program is not word!
#!e:\perl\bin\perl#如果用CGI方式来行动这个文件,请把下段路径改成你的机器配置
use  CGI;  $upfilecount  =  1;$maxuploadcount  =  2;  #限制上传文件的最大数$basedir  =  "e:/English";  #上传的文件存放地址$allowall  =  "no";  #是否不限制文件后缀上传@theext  =(".zip",".exe",".gif",".rm",".doc",".xls");  #要限制的文件后缀名$filesize = 220842;  #限制文件大小在216K
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  .  "  已成功上传!\n";       }       else{       $message.=$file&nb!
 sp;
 .  "  文件后缀不符合要求,上传失败!\n";       }        }else{     $message.=$file  .  "  文件后缀不符合要求,上传失败!\n";      }     }       $upfilecount++;       }
print  $message;  #最后输出上传信息  Beckett Richard-qswi266 <[EMAIL PROTECTED]> wrote:
All you need to get the file size is -s.I.e. $file_size = -s $fileSave the following script as size.pl, and run like this:perl size.pl size.pluse strict;use warnings;my $file = $ARGV[0];my $file_size = -s $file;print "$file is $file_size bytes\n";-Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tony CheungSent: 03 November 2004 06:54To: perl-win32-usersSubject: How to obtain filesize?I have a perl program about update file from pc to mysql,but I want to limit filesize,how to obtain filesize and file type?Do You Yahoo!?150万曲MP3疯狂搜,带您闯入音乐殿堂美女明星应有尽有,搜遍美图、艳图和酷图1G就是1000兆,雅虎电邮自助扩容!!
 Do You
 Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: How to obtain filesize?

2004-11-03 Thread Beckett Richard-qswi266
All you need to get the file size is -s.

I.e. $file_size = -s $file

Save the following script as size.pl, and run like this:

perl size.pl size.pl

use strict;
use warnings;
my $file = $ARGV[0];
my $file_size = -s $file;
print "$file is $file_size bytes\n";


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tony Cheung
Sent: 03 November 2004 06:54
To: perl-win32-users
Subject: How to obtain filesize?


I have a perl program about update file from pc to mysql,but I want to limit 
filesize,how to obtain filesize and file type?




Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!

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


Re: How to obtain filesize?

2004-11-03 Thread Alexander Apprich
Tony,

Tony Cheung wrote:
> I have a perl program about update file from pc to mysql,but I want to 
> limit filesize,how to obtain filesize and file type?
> 

for the file size you can use File::stat

use strict;
use warnings;
use File::stat;

my $file = "C:\\temp\\size.txt";

if ( -e "$file" ) {
   my $stat = stat($file);
   my $size = stat($file)->size;
   print "Size of $file is: " . $size . "\n";
} else {
   print "Could not fine $file\n" && die "\n";
}

for the file type you could query the extension by using a regex. Don't
know what you want to do with the file type, but if you want to exclude
a certain type of files you could do something like

  next if ( ( $file =~ /^.*\.exe$/i ) || ( $file =~ /^.*\.zip$/i ) );

Just a best guess.

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