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

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

#print header;

my $image_data;
my $data;
my $server = "burks";
my $image_filename;
my $prodID;
my $prod_name;

print "Product ID number: ";
chomp($prodID = <STDIN>);
print "Name of image file: ";
$image_filename = <STDIN>;
chomp($image_filename);
die unless $image_filename;
#my $mime = CGI::uploadInfo($image)->{'Content-Type'};

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

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

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

die unless $image_data;

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