#!/usr/bin/perl -w # FILE: upload_image.pl # Uploads gif images into database through a Perl Script. use DBI; my $image_data; my $data=''; #buffer to hold image info print "Name of file to upload: "; my $image_file = ; chomp($image_file); print "Abbreviation of State: "; my $ID = ; chomp($ID); my $mime = "image/jpg"; my $db = 'tsg'; my $server = '10.20.3.4'; open(FH, "$image_file") or die "Could not open file."; binmode(FH); while(read(FH, $data, 1024) ) { $image_data .= $data; } close(FH); die "image is empty" unless ($image_data); my $dbh = DBI->connect("dbi:mysql:$db:$server", "tgarrett", "waddy42") or die("Error! $!\nAborting"); $image_data = $dbh->quote($image_data); $mime = $dbh->quote($mime); $ID=$dbh->quote($ID); my $sql = qq{INSERT INTO IMAGE (IMAGE_ID, IMAGE_FILE_DATA,IMAGE_MIME) VALUES ($ID, $image_data, "image/image/jpg") }; my $sth = $dbh->prepare($sql) or die "could not prepare"; $sth->execute() or die ("Error: $DBI::errstr \nAborting"); print "Image file: $image_file of Type: $mime was successfully loaded into the database $db";