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.=$filenb! 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!?
150MP3
1G1000___
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 B1. 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 B2. 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
Iparam() to return an empty CGI parameter list.  You can test for
this event by checking Icgi_error(), either after you create the CGI
object or, if you are using the function-oriented interface, call
param() 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
Hi!
I used POST_MAX,and it's succeed,but the browser has not any result,why?
-
#!c:\perl\bin\perl#CGIuse 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!
 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_MAXIf 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_UPLOADSIf 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 B1. On a script-by-s!
 cript
 basisSet 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 B2. Globally for all scriptsOpen 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!?
150MP3
1G1000___
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/^.*(\\|\/)// 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 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
Please help me test this program,thanks!
Thank you very much!
---
upload.html
---
htmlbodyform method="POST" action=""http://localhost/cgi-bin/upload.pl">http://localhost/cgi-bin/upload.pl" ENCTYPE="multipart/form-data"File 1: input type="file" name="FILE1"brFile 2: input type="file" name="FILE2"brinput type="submit" value="Upload!"/form/body/html
===
--
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!br\n"; } else{ $message.=$file!
 p;
 . " file postfix error!br\n"; }  }else{ $message.=$file . " file too large!br\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!?
150MP3
1G1000___
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 . " !br\n"; } else{ $message.=$file!
 sp;
 . " !br\n"; }  }else{  $message.=$file . " !br\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!?150MP31G1000!
 Do You
 Yahoo!?
150MP3
1G1000___
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/^.*(\\|\/)// 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)  {  #Õâ¶Î¿ªÊ¼ÉÏ´«

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  .Òѳɹ¦ÉÏ´«!br\n;
}
else{
$message.=$filenb! sp; .   
 Îļþºó׺²»·ûºÏÒªÇó£¬ÉÏ´«Ê§°Ü!br\n;
}

  }else{
  $message.=$file  .   
 Îļþºó׺²»·ûºÏÒªÇó£¬ÉÏ´«Ê§°Ü!br\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-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


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!?
150MP3

1G1000

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


How to obtain filesize?

2004-11-02 Thread Tony Cheung
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!?
150MP3
1G1000___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs