#!/usr/bin/perl 
# FILE:  upload_image.cgi

use warnings;
use DBI;
use CGI qw(:standard);

#print header;

my $image_data;
my $data;
my $server = "clarke";
my $image_filename;
my $teamID;

print "Name of image file: ";
$image_filename = <STDIN>;
chomp($image_filename);
die unless $image_filename;

print "\nTeam ID Number: ";
chomp($teamID = <STDIN>);
die unless $teamID;

#my $mime = CGI::uploadInfo($image)->{'Content-Type'};

my $mime = "GIF Image";
my $db = 'NCAA_2006';

open(FH, $image_filename) or die "Error opening file";
binmode(FH);
while ( read(FH, $data, 2048) )
{
  $image_data .= $data;
}

my $dbh = DBI->connect("dbi:mysql:$db:$server", "tgarrett", "tgarrett1")
  or die("Error! $!\nAborting");

die unless $image_data;

$image_data = $dbh->quote($image_data);
$mime = $dbh->quote($mime);
my $sql = qq{INSERT INTO Logo (Logo_ID, Team_ID, image, mime)
  VALUES (0,$teamID, $image_data, $mime) };
my $sth = $dbh->prepare($sql);
$sth->execute 
  or die ("Error:  $DBI::errstr \nAborting");
print "success  MIME type: $mime\n"; 
