Hi, I'm new to unix/ Perl CGI. I have written Perl CGI scripts to upload a file into 2 servers at the same time using url redirection. But what happens is when i upload the file, it is getting uploaded in the first server properly and an empty file is uploaded in the second server( with the same filename- 0 bytes). An error saying: 'readline() on unopened filehandle at /var/apache/cgi-bin/uploadscr2 line 29 'comes in the error_log of the second server. I submit my script here:
( The follow script is in the cgi-bin of the first server-
http://server1 root/cgi-bin/uploadscr1)
#!/usr/bin/perl -w
use CGI;
$query = new CGI;
$upload_dir = "/usr/tmp";
$FILENAME = $query->param("photo");
$FILENAME =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("photo");
open UPLOADFILE, ">/usr/tmp/$FILENAME";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
print $query->redirect("
http://server2 root/cgi-bin/uploadscr2?file=$FILENAME&photo=$upload_filehandle");
==============================================
( this script is in the cgi-bin of the second server, the url mentioned above goes to this script)
#!/usr/bin/perl -w
use CGI;
$upload_dir = "/usr/tmp";
$q = new CGI;
print $q->header ( );
print " <HTML><HEAD></HEAD><BODY>";
$FILENAME = $q->param('file');
$FILENAME =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $q->upload('photo');
print " <BR>FILENAME = ".$FILENAME."<BR>";
open UPLOADFILE, ">/usr/tmp/$FILENAME";
binmode UPLOADFILE;
while ( <$upload_filehandle> ) # error message refers to this line
{
print UPLOADFILE;
}
close UPLOADFILE;
print "<P>Thanks for uploading a file!</P></BODY></HTML>";
=================================================
Please bare with me if my script is bad, but i will be very thankful if someone can clear my doubt.
Thank you in advance.