in reply to Having an issue with my CGI.pm file uploads

If you weren't getting the file opened, it shouldn't exist, even at zero bytes. You might want to test the return of the open() call and print any errors to make sure.
open my $output, '>', $localFile || die "Cannot write to $localfile: $!\n";
What's the size of the uploaded file? Are you sure it's longer than zero bytes in the temp directory after the upload? Perhaps it's a permissions issue with the upload. Why are you using binmode() on the output but not the input filehandle? You have no counter to see how may times you get lines in your while loop nor any test of the length of the lines. How can you be sure you're not writing exactly what there is to write?

Replies are listed 'Best First'.
Re^2: Having an issue with my CGI.pm file uploads
by technojosh (Priest) on Sep 25, 2007 at 16:49 UTC
    I am using binmode due to the filetypes that could be uploaded. I also think its odd that the file exists, but sure as heck it does, at 0 bytes, in the correct directory on the web server

    I do see your point about not testing the file, and it is valid. I probably cut some corners there, but only because I also am in control of the files that get uploaded.
    The one I'm testing with is ~7kb in size.

      You're not using binmode() on $upload_filehandle, though. You want to make sure you read in binary mode, too.

      As for file size, if you have binary data in the input file but it's not in binary mode, you could have issues there.

      Also, make sure you have a version of CGI.pm that doesn't have the fairly recent broken upload problem. CGI 3.21 and 3.22 simply don't work for uploads. See Skip CGI.pm versions 3.21 and 3.22 when upgrading -- they break the upload() method for more info. It could be you're not getting a file uploaded because the library really is broken.

      What does print $CGI::VERSION; give you?

        my CGI.pm version is 3.10

        If I try:

        my $upload_filehandle = $i->upload( 'JARFILE' ); binmode($upload_filehandle);
        I get the following error in my apache log:
        Can't use an undefined value as a symbol reference
        ...so now I am confused, why my filehandle is not getting defined. It is on a valid file upload field, as again, the file(complete with its remote name) is getting created at 0 bytes on the server.