Hello Monks,

I am trying to upload word docs, and/or images to a 2003 server. This is the error I keep getting: File upload: Bad file descriptor at D:\path\tofile.cgi line 67. I've been playing with this for a couple weeks now. Help!!

Here's the relevant code:
#! C:\perl\bin\perl use strict; use warnings; use diagnostics; use CGI; use CGI::Carp qw(fatalsToBrowser); use BKG::HTML::format; use BKG::INDEX::ver; my ($name, $ver, $comment, $T, $x, $i, $test1, $test2); my $y = 0; my $true=0; my $old = 0; my (@table_dat, @redata, @file_name, @file); # Some Security Holes Plugged $CGI::POST_MAX = 100 * 1024 * 1024; # limit posts to 100m max my $q = new CGI; ################# # Get form data # ################# $T=1; $x=1; #my @existing_files = BKG::INDEX::ver::Exists($name, $ver); while ($T) { $test1 = "name_upfile" . $x; $test2 = "upfile" . $x; if (($q->param($test1)) and ($q->param($test2))) { $file_name[$x-1] = $q->param($test1); $file[$x-1] = $q->upload($test2) or die "File upload: $!" +; # foreach (@existing_files) { # if ($file_name[$x-1] eq $_) { # print "Content-type: text/html\n\n"; # print "$_ already exists in this directory. Please c +hoose another name."; # exit; # } # } # if ( $file_name[$x-1] !~ /^([a-zA-Z\d_\s.]+)$/ ) { # print "Content-type: text/html\n\n"; # print "Only letters, numbers, underscores and whitespaces + are allowed in the upload name field!!"; # exit; # } # if ($file_name[$x-1] !~ /\.(jpg|gif|bmp|doc|txt)$/i) { # print "Content-type: text/html\n\n"; # print "Only JPG's, GIF's, BMP's, TXT's and DOC's are allo +wed to be uploaded!!"; # exit; # } $x++; } else { $T=0 } } # loop to upload docs and images $x=0; my ($bytesread, $buffer); foreach (@file_name) { open (OUTFILE, ">/web/aps/mi/$name/$ver/$_") or die "Cannot open $ +name: $!"; binmode(OUTFILE); while ($bytesread=read($file[$x],$buffer,1024)) { print OUTFILE $buffer; } close OUTFILE or die "Close:$!"; $x++; }
Any ideas and/or suggestions are welcome. Thanks in advance!

In reply to CGI Upload: Bad file descriptor by bkiahg

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.