I have a web tool that manages a set of java files. A feature of this tool is being able to upload java files, or update existing ones(also via an upload).

I had this script working (i thought), but now all uploaded files show up blank(0 bytes), and from this bit of code:

while ( <$upload_filehandle> ) { print UPLOADFILE; }
I get the following errors in my apache log:

Use of uninitialized value in <HANDLE>
readline() on unopened filehandle

Below is the complete code that handles the upload. The script seems to get the file info, because it does open a new file of the same name in the target directory, it just shows up as 0 bytes. I am wondering why $upload_filehandle is not getting opened correctly?
Environment: win32, apache server

use CGI; my $i = new CGI; my $ieFileMod; my $upload_filename = $i->param( 'JARFILE' ); my $upload_filehandle = $i->upload( 'JARFILE' ); # handle copying the file to server $upload_filename =~ m/^.*(\\|\/)(.*)/; # strip the remote path and kee +p the filename # still need to do something if its IE submitted file, since above reg +ex doesn't clean up filename for IE if( $upload_filename =~ /\\/ ) { my @nameList = split( /\\/, $upload_filename ); $ieFileMod = pop( @nameList ); } my $finalName = $upload_filename; if( $ieFileMod ) { $finalName = $ieFileMod; } my $localFile = "java\\$finalName"; # copy the jar file in binary mode to server open UPLOADFILE, ">$localFile"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;

In reply to Having an issue with my CGI.pm file uploads by technojosh

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.