datannen has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I have a very simple form:
<FORM action="/cgi-bin/test.cgi" method="post" enctype="multipart/form +-data"> <input value="1154632892005" name="unique" type="hidden"> <INPUT TYPE="FILE" NAME="file"> <INPUT type="submit" value="Send"> <INPUT type="reset"> </FORM>
I want to store the data stream as it uploads to: /tmp/1154632892005/postdata
use CGI; use Fcntl qw(:DEFAULT :flock); my $cgi = new CGI; $user_dir = "/tmp/1154632892005"; open(TMP,">","$user_dir/postdata") or &bye_bye ("can't open temp file" +); my $i=0; $ofh = select(TMP); $| = 1; select ($ofh); while (read (STDIN ,$LINE, 4096) && $bRead < $len ) { $bRead += length $LINE; $size = -s "$user_dir/postdata"; select(undef, undef, undef,0.35); # sleep for 0.2 of a s +econd. $i++; print TMP $LINE; } close (TMP);
However, I wind up with nothing in postdata. This same process works if I do not use enctype="multipart/form-data" Help?

Replies are listed 'Best First'.
Re: multipart/form-data files
by chromatic (Archbishop) on Aug 07, 2006 at 23:25 UTC
Re: multipart/form-data files
by kwaping (Priest) on Aug 07, 2006 at 23:19 UTC
    Is that an exact copy and paste of your code, or did you re-type it? Because you define $userdir but then use $user_dir in the rest of the lines.

    ---
    It's all fine and dandy until someone has to look at the code.
Re: multipart/form-data files
by gellyfish (Monsignor) on Aug 08, 2006 at 07:39 UTC

    The form data on STDIN will be read in full as soon as you do y $cgi = new CGI; after that you can access the form fields using the $cgi->param() method and you can get a filehandle to the uploaded "file" data using the $cgi->upload() method. You can read about dealing with "file upload fields" in the CGI documentation.

    /J\

Re: multipart/form-data files
by Anonymous Monk on Aug 11, 2006 at 10:57 UTC