S
Stuart Weaver
hello, I am fairly new to perl, please bare with me.
I have written a perl script that is intended to be use via cgi.
Given search parameters of a first and/or last name the script searches a
mysql database and in return is intended to display an image of that person.
The desired result is to display the image in-line on the fly, I do not wish
to write the file to disk and then use a 'img src' html tag to display the
image. The problem I am having is the image is displayed in binary format. I
believe I am displaying the data retrieved from the mysql database incorrectly.
I would greatly apricate any help. Thanks in advance.
Stuart
Snip-it of code follows:
If including the whole script would help please let me know.
$sql = qq{ SELECT image FROM pic WHERE fn = ? or ln = ? };
$sth = $dbh->prepare($sql);
$sth->execute($fn,$ln);
my $pic = $sth->fetchrow_array || "";
if ( "$pic" eq "" ) { print "Nothing Found \n\n"; }
else
{
print "<td align=\"center\"> \n";
print "$fn $ln <br><br> \n";
my $image_type;
if (substr($pic,0,3) =~ 'GIF' )
{
$image_type = 'image/gif';
}
elsif (substr($pic,0,10) =~ 'JFIF' )
{
$image_type = 'image/jpeg';
}
print "$image_type \n";
print $pic;
print "<br> \n";
}
I have written a perl script that is intended to be use via cgi.
Given search parameters of a first and/or last name the script searches a
mysql database and in return is intended to display an image of that person.
The desired result is to display the image in-line on the fly, I do not wish
to write the file to disk and then use a 'img src' html tag to display the
image. The problem I am having is the image is displayed in binary format. I
believe I am displaying the data retrieved from the mysql database incorrectly.
I would greatly apricate any help. Thanks in advance.
Stuart
Snip-it of code follows:
If including the whole script would help please let me know.
$sql = qq{ SELECT image FROM pic WHERE fn = ? or ln = ? };
$sth = $dbh->prepare($sql);
$sth->execute($fn,$ln);
my $pic = $sth->fetchrow_array || "";
if ( "$pic" eq "" ) { print "Nothing Found \n\n"; }
else
{
print "<td align=\"center\"> \n";
print "$fn $ln <br><br> \n";
my $image_type;
if (substr($pic,0,3) =~ 'GIF' )
{
$image_type = 'image/gif';
}
elsif (substr($pic,0,10) =~ 'JFIF' )
{
$image_type = 'image/jpeg';
}
print "$image_type \n";
print $pic;
print "<br> \n";
}