Most people don't seem to think of using -s on the filehandle provided by CGI::Simple (or CGI). The following script works just fine (ugly example, but it works). You will notice one problem with this however: it works for the reading, but the entire file has to be uploaded before processing can begin. As far as I know, this problem exists in every single upload and cannot be avoided. The code in the script won't even start executing until the client has passed the entire file upload contents.

#!c:/perl/bin/perl -w $| = 1; use strict; use CGI::Simple qw(-upload); my $q = CGI::Simple->new(); if ( defined($q->param('fh_upload')) ) { my $fh = $q->upload( $q->param('fh_upload') ); my $size = -s($fh); print $q->header(), <<'END_HTML'; <html> <head> <title>Upload Example</title> </head> <body> END_HTML my ($uploaded, $buffer); while ( my $bytes = read($fh, $buffer, 1024) ) { $uploaded += $bytes; print int($uploaded / $size * 100), "%<br />\n"; select( undef, undef, undef, 0.02); } print "</body></html>"; } else { print $q->header(); print <<"END_HTML"; <html> <head> <title>Upload Example</title> </head> <body> <form action="${\($ENV{'REQUEST_URI'})}" method="post" enctype +="multipart/form-data"> File to Upload: <input type="file" name="fh_upload" size=" +30" /> <input type="submit" value="upload file" /> </form> </body> </html> END_HTML }

In reply to Re: Upload Progress by Anonymous Monk
in thread Upload Progress by Ganlron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.