technojosh has asked for the wisdom of the Perl Monks concerning the following question:
I had this script working (i thought), but now all uploaded files show up blank(0 bytes), and from this bit of code:
I get the following errors in my apache log:while ( <$upload_filehandle> ) { print UPLOADFILE; }
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;
|
|---|