Hi,
I would appreciate if someone could help me out on a file upload subroutine I
shamelessly copied and modified from CGI Programming with PERL by S. Gundavaram et al.
The program is as follows
#!/usr/bin/perl
# CGI Programming with Perl by Shishir Gundavaram et al Chapter 5 CGI.pm: File uploads
with CGI.pm
use strict;
use warnings;
use CGI;
use Fcntl qw( :DEFAULT :flock );
my $q = new CGI;
my $file = $q->param("file");
my $fh = $q->upload($file);
my $buffer = '';
use constant BUFFER_SIZE => 16_384;
use constant MAX_FILE_SIZE => 1_048_576;
$CGI::DISABLE_UPLOADS = 0;
$CGI::POST_MAX = MAX_FILE_SIZE;
.
. skip some lines
.
# ...print variables
print <<CHECK_ME;
<PRE>
FILE NAME --> $file
FILE HANDLE --> $fh
</PRE>
CHECK_ME
# Write file content to output file
sysopen (OUTPUT,'/xxx/cgi/my_dir/my_file_upload.txt', O_CREAT | O_RDWR | O_EXCL);
while (read($fh, $buffer, BUFFER_SIZE)) {
print (OUTPUT $buffer);
}
exit;
What I want to do is to upload a file and save it content in my_dir as
my_file_upload.txt. To see values $file and $fh have I print them to the browser.
The trouble appears to be with uninitialization of $fh at
my $fh = $q->upload($file);
Suggestions?
Thanks in advance,
Serguei
---------------------------------
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online