I made this script but, i dont seem to get the $in{'filename'} into the $data var.
who can point me into a direction?
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "tecline.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
use vars qw($use_html $date $time);
};
if ($@) {
print "HTTP/1.0 200 OK\n";
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
#
$|++;
$use_html = 0;
$ENV{'REQUEST_METHOD'} and $use_html++;
$use_html and (%in = &parse_form);
&upload_all;
}
sub upload_all {
# --------------------------------------------------------
# Upload the job database.
# Determine if we are printing to command line, or to browser.
$nph++;
&html_print_headers() if ($use_html);
my $start = time();
my $date = &get_date;
my $time = &get_time;
# Print HTML Header
$use_html ?
print qq|<html><head><tittle>TecLine: Upload File</title></head>
<BASE TARGET="_top">
<BODY BGCOLOR="#DDDDDD"><H2><TT>Upload File</TT></H2>
<PRE>| :
print qq|Upload File\n|;
print "File uploading on " . $date . " at " . $time . "\n";
print "--------------------------------------------------------\n\n";
# Backup the database.
print "Uploading . . .\n";
&upload;
print "Done.\n\n";
# We are finished!
print "Finished at (", time() - $start, " s)!";
print "</PRE></BODY></HTML>" if ($use_html);
}
sub upload {
# -----------------------------------------------------
# Begin Upload File Procedure:
my ($data, $bytesread, $buffer, $fullfile, $file_size);
$file_size = 0;
$data = $in{'filename'};
# Make sure we have a filename to upload.
(!$data) and &cgierr("Can't Upload: please specify a filename. Reason: $!");
# Open the output file and save the upload. We abort if the file is
# to big, or not enough free disk space.
open (OUTFILE, ">$db_job_name.upload") or &cgierr ("Can't open: $db_job_name.upload. Reason: $!");
binmode (OUTFILE); # For those O/S that care.
while ($bytesread=read($data,$buffer,1024)) {
($filename =~ /cgi|pl$/) and ($buffer =~ s/\r//g);
print OUTFILE $buffer;
$file_size += 1024;
}
close OUTFILE;
if (-e "db_job_name.upload") {
print "\tFile uploading...\n";
return;
}
}
1;
who can point me into a direction?
Code:
# Required Librariers # --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "tecline.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
use vars qw($use_html $date $time);
};
if ($@) {
print "HTTP/1.0 200 OK\n";
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
#
$|++;
$use_html = 0;
$ENV{'REQUEST_METHOD'} and $use_html++;
$use_html and (%in = &parse_form);
&upload_all;
}
sub upload_all {
# --------------------------------------------------------
# Upload the job database.
# Determine if we are printing to command line, or to browser.
$nph++;
&html_print_headers() if ($use_html);
my $start = time();
my $date = &get_date;
my $time = &get_time;
# Print HTML Header
$use_html ?
print qq|<html><head><tittle>TecLine: Upload File</title></head>
<BASE TARGET="_top">
<BODY BGCOLOR="#DDDDDD"><H2><TT>Upload File</TT></H2>
<PRE>| :
print qq|Upload File\n|;
print "File uploading on " . $date . " at " . $time . "\n";
print "--------------------------------------------------------\n\n";
# Backup the database.
print "Uploading . . .\n";
&upload;
print "Done.\n\n";
# We are finished!
print "Finished at (", time() - $start, " s)!";
print "</PRE></BODY></HTML>" if ($use_html);
}
sub upload {
# -----------------------------------------------------
# Begin Upload File Procedure:
my ($data, $bytesread, $buffer, $fullfile, $file_size);
$file_size = 0;
$data = $in{'filename'};
# Make sure we have a filename to upload.
(!$data) and &cgierr("Can't Upload: please specify a filename. Reason: $!");
# Open the output file and save the upload. We abort if the file is
# to big, or not enough free disk space.
open (OUTFILE, ">$db_job_name.upload") or &cgierr ("Can't open: $db_job_name.upload. Reason: $!");
binmode (OUTFILE); # For those O/S that care.
while ($bytesread=read($data,$buffer,1024)) {
($filename =~ /cgi|pl$/) and ($buffer =~ s/\r//g);
print OUTFILE $buffer;
$file_size += 1024;
}
close OUTFILE;
if (-e "db_job_name.upload") {
print "\tFile uploading...\n";
return;
}
}
1;