[Buffalo-pm] CGI.pm uploadinfo filesize

DANIEL MAGNUSZEWSKI dmagnuszewski at mandtbank.com
Fri Mar 3 07:52:15 PST 2006


Check out these sites (donated by one of those "PHP Guys" within PM):

http://www.raditha.com/megaupload/perl.php 
http://sourceforge.net/projects/megaupload/ 

-Dan

>>> "Jim Brandt" <cbrandt at buffalo.edu> 03/03/06 10:40 AM >>>
Check out the code for the valid_file_max_bytes method in this module:

http://search.cpan.org/src/MARKSTOS/Data-FormValidator-4.14/lib/Data/FormValidator/Constraints/Upload.pm


If you trace it through, you'll see they use CGI.pm 'upload' method to

get a filehandle to the uploaded file. Then they just stat the file.

	my $fh = _get_upload_fh($self);
	if (!$fh) { warn "Failed to load filehandle for $field" &&
return undef; }

	## retrieve size
    	my $file_size = (stat ($fh))[7];

I don't think this will really solve your problem, though. To display 
progress, you need to know the size of the file ahead of time. But you

can't know this until you've already got the file on your file system.

If you want a progress indicator, you just need to make a fake one.



DANIEL MAGNUSZEWSKI wrote:
> This page may help a little - check out the bottom of the last
example
> (http://perlmeme.org/tutorials/cgi_upload.html):
> 
> 
>         while ($bytesread = read($filename, $buffer, $num_bytes)) {
>             $totalbytes += $bytesread;
>             print OUTFILE $buffer;
>         }
> 
> I can't find anything on it right now, but I was told that there is
a
> "FILE" (or something similar) entry in the %ENV (environment
variable)
> hash. It should contain a whole bunch of information on the file
(name,
> size, etc). If this is the case, then you can simply grab the
filesize
> and use the above while loop and compare the bytes read with
whatever
> the total number of bytes is. 
> 
> I'm not a "web guy" so I'm not too familar with using %ENV beyond
its
> basic uses. Does anyone else know if the filesize is in %ENV?
> 
> -Dan
> 
> 
>>>> <joshj at linuxmail.org> 03/01/06 6:20 PM >>>
> How exactly do you get the filesize of an uploaded file? I'd like to
> use
> it so I could display progress to the user. Everything seems to say
to
> use uploadInfo from CGI.pm or upload_info from CGI::Simple. The only
> one
> that even returns anything useful is CGI.pm. It gives me
content-type,
> content-disposition, name, and filename. But no file size. So I'm
> thinking that maybe there is something more I should specify in the
> html
> to tell the client that I want that information. Here is my html
form:
> 
> <form method="post" action="oldup.cgi"
enctype="multipart/form-data">
> <input type="file" name="upfile" /><input type="submit" /></form>
> 
> and the cgi:
> 
> use strict;
> use CGI qw(:standard uploadInfo);
> use Data::Dumper;
> 
> my $q = new CGI;
> my $fname = param('upfile');
> my $fsize = $q->uploadInfo($fname);
> print <<"html";
> Content-type: text/html
> 
> <h1>UpLoad File</h1>
> 
> file: $fname<br />
> 
> <b>Done $fsize</b>
> html
> print Dumper($fsize);
> 
> ------------------------------
> Any ideas how to get this information?
> 
> -Josh J
> _______________________________________________
> Buffalo-pm mailing list
> Buffalo-pm at pm.org 
> http://mail.pm.org/mailman/listinfo/buffalo-pm 
> 
> 
> _______________________________________________
> Buffalo-pm mailing list
> Buffalo-pm at pm.org 
> http://mail.pm.org/mailman/listinfo/buffalo-pm 

-- 
Jim Brandt
Administrative Computing Services
University at Buffalo





More information about the Buffalo-pm mailing list