It's one of those crazy situations were I'm using a chunk of code in dozens of places and all have worked fine, including on this very site that is causing the error:

Cannot read sourcefile: Bad file descriptor at...

This question has been asked before, but the solution doesn't apply here (my html is fine).

It opens the file (I see it in the directory) but it has 0 bytes. Permissions for the folders are 0755 and I've tried eliminating the path thinking that was it. I've tried everything I can think of and to no avail. Ideas? TIA!

HTML: <form action="some.cgi" method="post" enctype="multipart/form-da +ta"> PERL: my $image = $query->param('image'); my $lgimage = &upload_file($image,"../acme/images/products"); . . . sub upload_file { $| = 1; #flush the output buffer my ($sourcefile,$path) = @_; my ($buffer, $bytes); $sourcefile =~ /([\w .-]+)$/i; #strip off path stuff my $newfile = $1; $newfile =~ s/ //; open (OUTFILE, ">$path/$newfile") or die "Cannot open $newfile: $!" +; binmode(OUTFILE) or die "Cannot binmode: $!"; while (read($sourcefile, $buffer, 1024) or die "Cannot read sourcef +ile: $!") { print OUTFILE $buffer or die "Cannot print to buffer: $!"; } close(OUTFILE) or die "Close: $!"; chmod (0664, ">$path/$newfile") or die "Cannot chmod: $!"; return ($newfile); }


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to Bad file descriptor when uploading file via CGI by bradcathey

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.