in reply to Re: Re (tilly) 1: Uploads (again!)
in thread Uploads (again!)

It isn't a surprise to you that the file "UPLOAD" doesn't exist and thus can't be opened on Line 17, right? Its a good idea esp. w/ us novices, it to comment every single goldurn close bracket w/ what its closing (even just 2 lines) e.g.
for my $file (sort grep /file/, param()) { print p(); my $handle = upload($file); open (IMAGE, ">$handle") || die "Couldn't open $handle: $!"; my $buffer; while (read($handle, $buffer, 10240)) { print IMAGE $buffer; } # while read or for my file sort ??? unless (defined($handle)) { if ($file =~ /(\d+)/) { print h3("File request $1 did not return a handle\n"); } # if $file =~ \d next; } # unless def $handle print p(), h3("Uploaded $handle"), br(), "<pre>"; print encode_entities($_) while <$handle>; print "</pre>"; } # for my $file sort
So, if handle isn't defined, why print to it? Why don't you have -w up there? How about sort grep /file\d+/ to get only the file0-9+ params? Why not put a few debugs in along the way: print STDERR "Trying file $file\n"; before the upload stmt. Maybe an "if (-s $file)" to be sure $file exists. As the tilly said, its not about getting this one to work, its about learning how to get scripts in general to work. You know UPLOAD isn't the file, so how did you get the name? From your for sort grep loop. What else is that returning? Use STDERR to put debug to the error logs so you can watch as the script progresses.

I like to use
print STDERR "trying file $file in forloop\n" if $debug > 3;
and then use "my $debug = X" as needed. You'll often find you need to turn debugging back on, and by using different levels for different levels of detail, you can leave all your debugs in (my $debug = 0) and turn on those you need as you change stuff.

a