Hello! I am trying to upload a file using a perl script. When I submit the file, everything on the next page loads, the only problem is that the file isn't located in the upload directory! I'm not sure why it isn't working..can anyone give me a hand? Thanks!
#use strict;
use warnings;
use CGI qw(:standard);
use Win32::OLE;
use Mail::Sendmail;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
use Win32::OLE::Variant;
use Win32::ODBC;
use HTML::Entities;
use String::Util ':all';
#custom modules
use DxMod::GetTime;
#getting the post array so that
#it is printable
#such as: $Form{field}
my %Form;
foreach my $field (param()){
$Form{$field} = param($field);
$Form{$field} = crunch($Form{$field});
$Form{$field} = unquote($Form{$field});
$Form{$field} = define($Form{$field});
$Form{$field} =~ s/\'//g;
$Form{$field} =~ s/\"//g;
}
#This is the
#subroutine
# SEND MAIL
sub mail{
my $message = "$Form{vdesc}";
unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'mail.dxa.com';
%mail = ( To => 'xxx@xx.com',
From => "$Form{vuser}\@dxa.com",
Subject => "Support!",
Message => $message
);
sendmail(%mail) or die $Mail::Sendmail::error;
}#sub mail
&mail();
###########
#Handle the file upload
###########
$CGI::POST_MAX = 30048;
my $cgi = new CGI;
my $dir = "cdavissandbox/upload";
my $file = $cgi->param('file');
if ($file)
{
$file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename
$name = $2;
open(LOCAL, ">$dir/$name") or die $!;
binmode LOCAL;
while(<$file>) {
print LOCAL $_;
}
close LOCAL;
#getting the 2 dates for the DB
my $theTime = TimeDate();
my $subdate = TimeDate("date");
#My database code
my $sql = "INSERT into support_calls (ID, vdate, vdesc, vuser) VALUES ('$theTime', '$subdate', '$Form{vdesc}', '$Form{vuser}')";
if ($file)
{$sql = "INSERT into support_calls (ID, vdate, vdesc, vuser, vfile)
VALUES ('$theTime', '$subdate', '$Form{vdesc}', '$Form{vuser}', '$dir/$name')";}
my $db = Win32::ODBC->new('support');
$db->Sql($sql);
$db->Close();
print'
<html>
<head>
<title>Support!</title>
</head>
<body>
<div style="border:2px;border-style:dashed;width:50%;margin:10px;padding:15px;">
Thank you for submitting a request to Support! We will take care of it
as soon as we are able. Please check your E-mail periodically because we may need more information about
the issue. Thanks!<br/><br/>
';
if ($message){print $message;}
print'
<a href="javascript:history.go(-1)">[Submit Another Request]</a>
<a href="">[Go Home]</a>
</div>
</body>
</html>';
Bookmarks