bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bad file descriptor when uploading file via CGI
by Errto (Vicar) on Apr 07, 2005 at 04:06 UTC | |
by bradcathey (Prior) on Apr 07, 2005 at 08:07 UTC |