hi,
i m working on a perl cgi script which uploads a file to the server. i m stuck. i hav written the errors.
plz help.
Sachin Kaw
______________________________________________________________________
#!/usr/bin/perl -w
use CGI;
use CGI qw(:standard);
use strict;
use POSIX qw(strftime);
use Spreadsheet::WriteExcel;
#use HTML::EasyTable;
use POSIX qw(tmpnam);
use CGI::Carp qw(carpout);
$CGI::POST_MAX=1024 * 5000; # max 5MB posts
my $logfile = "/tmp/upload-mylog.log";
BEGIN {
use CGI::Carp qw(carpout);
open(LOG, ">>/tmp/upload-cgi.log") or
die("Unable to open cgi.log: $!\n");
carpout(\*LOG);
}
# your custom running log function
sub mylog
{
my $curtime = strftime "%a %b %d %T", localtime;
my $curfunc = (caller(1))[3];
if\( !defined $curfunc \)\{
$curfunc = "main:";
\}
my $FL;
open\( FL, ">>$logfile" \) || die "could not open file";
print FL "$curtime: $curfunc: $_[0]\\n"; \# This line prints to the log
close \(FL\);
}
my $q = new CGI;
\#my $filename='filename';
my $upload_filehandle;
mylog \( "______ mylog \( \_\_LINE__ . ": Before entering if block" \);
if \(param\(\)\) \{
mylog \( \_\_LINE__ . ": We have the form populated." \);
\# upload directory
my $upload_dir = "/home/skw";
\# reading the form variables
my $filename = $q->param\('filename'\);
mylog\("filename = $filename"\);
$filename =~ s/.\*[\\/\\\\]\(.*\)/$1/;
mylog\("file = $filename"\);
\# getting the file handle
$upload_filehandle = $q->upload\('filename'\);
mylog\("fd = $upload_filehandle"\); \#error 1
\# saving the file
open \(OUTFILE, ">$upload_dir/$filename"\);
\#binmode UPLOADFILE;
while \( <$upload_filehandle> \) $error 2 & 3
\{
print OUTFILE $_;
\}
close OUTFILE;
print $q->header\(\);
\#print <<END_HTML;
\}
else \{
mylog \( \_\_LINE__ . ": Form is not populated." \);
\#$strhtml .= $q->end_html;
\}
___________________________________________________________________________
error 1:- Use of uninitialized value in <HANDLE>
error 2:- Use of uninitialized value in concatenation (.)
error 3:- readline() on unopened filehandle