in reply to file upload (again)

You can only run this code from another form that provides the filename and handle, without them you get the error. I've added a simple form to your script to prove it works OK
#!perl -wT use CGI qw(:standard); #### be sure to change this use CGI::Carp qw ( fatalsToBrowser ); use strict; use Fcntl qw ( :DEFAULT :flock ); use constant UPLOAD_DIR => "c:/upload/"; my $q = new CGI; my $filename = $q->param('file'); my $fh = $q->upload('file'); if ($fh){ #### check for filehandle $filename =~ s/[^\w.-]/_/g; if ($filename =~ /^(\w[\w.-]*)/) { $filename = $1; } else { error($q, "Invalid file name." ); } my $upload_dir = UPLOAD_DIR . $filename; sysopen(OUTPUT, $upload_dir, O_CREAT | O_RDWR | O_EXCL); my $buffer = ""; while (read($fh, $buffer, 16384)) { print OUTPUT $buffer; } close OUTPUT; print $q->header, $q->start_html("At long last"), $q->h1("done dude...doh"), #### add button to reset form $q->start_form( -action => url () ), $q->submit ( -name=>"done", -value=>"Done"), $q->end_form(); #### $q->end_html; #### simple form to choose file to upload } else { print $q->header, $q->start_html("Upload File"), $q->start_multipart_form( -action => url () ), "File : ", $q->filefield (-name=>"file", -size=>60), $q->submit ( -name=>"submit", -value=>"Submit"), $q->end_form(); $q->end_html; }
poj