Here is an abbreviated copy of the code:
sub CheckSave{
my $id = $_[0]; #passing primary key
my $url = $_[1]; #whether or not to save backup
my $savepath = $_[2];
#check web page header to see if it exists
@dat=head($url);
if (!@dat) {
print <<EOF;
<DIV STYLE="color:red;border:solid 2px red; padding:4px;">
System cannot contact the Internet to save a backup. Please contact the webmaster
or edit the web address entered.<BR>
URL: $url
</DIV>
EOF
;
die;
}
#get extension for saved file from url
$ext=$in{"cec_url"};
if ($ext =~ /\?/ ¦¦ $ext =~ /.com$/) {
#if url contains a query string, use header to return extension
#if .com address, use content_type
$ext=$dat[0];
$ext =~ s/.*\/(.*)/\1/;
} else {
#otherwise, find the file type from the url
$ext =~ s/.*\.([^\/]*)/\1/;
}
#save the new web download
$saveFile = $savepath.$id.".".$ext; #generate archive file name
$status = getstore($in{"cec_url"}, $saveFile); #check url and save copy
if (is_success($status)) {
print qq[<BR><CENTER>Backup copy saved.</CENTER>\n];
} else {
#print warning if website was not valid
print <<EOF;
<DIV STYLE="color:red;border:solid 2px red; ">
Website link not found. Archive file not saved.<BR>
Please edit this record.
</DIV>
EOF
;
}
}