M
Mark Constant
I looked at a couple of scripts on how to upload a file and came up
with the script below. Now the script acts like it uploaded the file
by not giving errors but when I check the directory no file is there.
The script runs from /cgi-bin/ and the quickbooks directory is chmod
755. What I am trying to do is upload a quickbooks file that is 50mbs.
Here are the most important parts. I only left out how I got the time
and date.
#!/usr/bin/perl
use CGI;
$q = new CGI;
$file = $q->param("upfile");
$dir = "../htdocs/quickbooks";
$filename = "$file-$date-$time";
print $q->header, $q->start_html("Uploading File");
print $q->h1("Upload Results");
if(!file){
print "Nothing Uploaded\n";
} else {
print "Filename: $filename<br />\n";
$ctype = $q->uploadInfo($file)->{'Content-Type'};
print "MIME Type: $ctype<br />\n";
open(OUTFILE, ">$dir/$filename") or dienice("Can't upload file: $!
\n");
binmode(OUTFILE);
while (my $bytesread = read($file, $buffer, 1024)) {
print OUTFILE $buffer;
}
close(OUTFILE);
print "File saved\n";
}
$q->end_html;
sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}
with the script below. Now the script acts like it uploaded the file
by not giving errors but when I check the directory no file is there.
The script runs from /cgi-bin/ and the quickbooks directory is chmod
755. What I am trying to do is upload a quickbooks file that is 50mbs.
Here are the most important parts. I only left out how I got the time
and date.
#!/usr/bin/perl
use CGI;
$q = new CGI;
$file = $q->param("upfile");
$dir = "../htdocs/quickbooks";
$filename = "$file-$date-$time";
print $q->header, $q->start_html("Uploading File");
print $q->h1("Upload Results");
if(!file){
print "Nothing Uploaded\n";
} else {
print "Filename: $filename<br />\n";
$ctype = $q->uploadInfo($file)->{'Content-Type'};
print "MIME Type: $ctype<br />\n";
open(OUTFILE, ">$dir/$filename") or dienice("Can't upload file: $!
\n");
binmode(OUTFILE);
while (my $bytesread = read($file, $buffer, 1024)) {
print OUTFILE $buffer;
}
close(OUTFILE);
print "File saved\n";
}
$q->end_html;
sub dienice {
my($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}