abecedae has asked for the wisdom of the Perl Monks concerning the following question:


Cannot recover usable filehandle from CGI.pm.


I am going pretty much straight from the O' Reilly CGI Programming book entering a program that uploads files to the server. Using Apache 2.0.49 on Windows XP. (leaving out error checks here for simplicity)
my $q = new CGI; my $file = $q->param( "file" ) #this is passed correctly my $fh = $q->upload( $file ); #this returns "" #Necessary for non-unix systems ####binmode $fh;#### binmode OUTPUT; #write contents to output file ####while ( read( $fh, $buffer, BUFFER_SIZE ) ) {#### #### print OUTPUT $buffer; #### ####} #### close OUTPUT;
Decommenting any of the quadruple# causes errors. Any thoughts?

Replies are listed 'Best First'.
Re: Filehandles with CGI.pm
by NetWallah (Canon) on Jun 22, 2004 at 01:01 UTC
    From the CGI Docs:

    the upload() function (new in version 2.47). When called with the name of an upload field, upload() returns a filehandle, or undef if the parameter is not a valid filehandle.(My Emphasis)

    So, what you need to do to get the file HANDLE is: (Untested)

    my $fh = $q->upload( "file" );

    Earth first! (We'll rob the other planets later)

      Excellent! (typo in the book) Thanks
        Really? Which version of CGI.pm is mentioned in the book? When was the book published (isbn)?
Re: Filehandles with CGI.pm
by neeraj (Scribe) on Jun 22, 2004 at 10:26 UTC
    I think u are talkig of CGI programming with perl -by O reilly , the problem is given in the example 5.2 , chapter 5. Plz look at it.