Hi, goBoating. Your script for file uploading is working but I run into a problem. I would like to use the script as part of another script I'm working on but this script uses 'standard' CGI and not 'my CGI'. Sorry for the poor explanation, I don't know how the different sorts of Perl are called but I think you understand what I'm trying to say.
I did two things:
1. Use your script as a seperate script and call it with 'require'. It didn't work.
2. Re-wrote your script into 'standard' CGI which didn't work neither. The variable can't be read into the script which resulted in a fatal error because it couldn't open the destination file.
Are you or anybody else able to give an hint how I can solve this problem? Is it possible to switch to 'my CGI' within a script and switch back to 'standard' CGI?
this is a stripped version of how I changed the script:
#!/usr/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$input{$name} = $value;
}
print "Content-type: text/html\n\n";
$fileID= $input{'fileID'};
print "$fileID<BR>\n";
@pathName = split(/\\/,$fileID);
# if $fileID is not null, read file from remote machine and write locally.
$newFile = '/home/andasoft/images/';
$newFile .= pop(@pathName);
# open a handle to the file you will write
open(OPF,">$newFile" || &showError("Failed to open OPF, $!"
# while you read from the remote machine, write to the output file.
while ($bytesread=read($fileID,$buffer,1024)) { print OPF "$buffer"; }
close OPF;
sub showError
{
# a generic complaint generator
my @error = @_;
print "<CENTER><font color=\"\#ff4500\">Fatal ERROR - @error</font><BR>\n";
print "Submission aborted - your data was not saved!!<BR>\n";
print "Please use the BACK button to return to the previous page<BR>\n";
print "and correct the error.<BR></CENTER>\n";
print $query->end_form,$query->end_html;
exit;
}
Jett,
[sig][/sig]
I did two things:
1. Use your script as a seperate script and call it with 'require'. It didn't work.
2. Re-wrote your script into 'standard' CGI which didn't work neither. The variable can't be read into the script which resulted in a fatal error because it couldn't open the destination file.
Are you or anybody else able to give an hint how I can solve this problem? Is it possible to switch to 'my CGI' within a script and switch back to 'standard' CGI?
this is a stripped version of how I changed the script:
#!/usr/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$input{$name} = $value;
}
print "Content-type: text/html\n\n";
$fileID= $input{'fileID'};
print "$fileID<BR>\n";
@pathName = split(/\\/,$fileID);
# if $fileID is not null, read file from remote machine and write locally.
$newFile = '/home/andasoft/images/';
$newFile .= pop(@pathName);
# open a handle to the file you will write
open(OPF,">$newFile" || &showError("Failed to open OPF, $!"
# while you read from the remote machine, write to the output file.
while ($bytesread=read($fileID,$buffer,1024)) { print OPF "$buffer"; }
close OPF;
sub showError
{
# a generic complaint generator
my @error = @_;
print "<CENTER><font color=\"\#ff4500\">Fatal ERROR - @error</font><BR>\n";
print "Submission aborted - your data was not saved!!<BR>\n";
print "Please use the BACK button to return to the previous page<BR>\n";
print "and correct the error.<BR></CENTER>\n";
print $query->end_form,$query->end_html;
exit;
}
Jett,
[sig][/sig]