Braindead_One has asked for the wisdom of the Perl Monks concerning the following question:
Hello fellow Monks!
I'm currently writing a small CGI-Script that, among other things, tries to feed images from a Mysql-DB to the browser.
But for some strange reason i can't read both content-type and data from within the same SQL-Statement:
$type should be 'image/gif', 'image/png' or 'image/jpeg', depending on the output of Image::Info.my $sql = "select type,data from bilder where id =?"; my $sth = $dbh->prepare($sql); $sth->execute( $q->param('id') ); my $error = 0; (my $type, my $data) = $sth->fetchrow() || ( $error = 1 ); binmode(STDOUT); if ( $error == 1 ) { print $q->header( -type => "image/gif" ); open( IN, "templates/keinbild.gif" ); binmode(IN); while (<IN>) { print; } close(IN); } else { print $q->header( -type => $type ); print $data; }
Adding a warn($type) gives:
DB is as follows:[Sun Dec 18 11:24:34 2005] [error] [client 192.168.x.y] (\xa2\x80, ref +erer: http://server.lan/cgi-bin/index.pl?action=picman
Does anyone know what's wrong here?CREATE TABLE `bilder` ( `id` int(11) NOT NULL auto_increment, `data` longblob NOT NULL, `type` enum('image/jpeg','image/gif','image/png') NOT NULL default ' +image/jpeg', `resx` int(11) NOT NULL default '0', `resy` int(11) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
Thank you in advance
Braindead_One
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mysql and Images
by gloryhack (Deacon) on Dec 19, 2005 at 09:01 UTC | |
by Happy-the-monk (Canon) on Dec 19, 2005 at 09:46 UTC | |
by gloryhack (Deacon) on Dec 19, 2005 at 19:00 UTC | |
by Braindead_One (Monk) on Dec 19, 2005 at 19:56 UTC | |
by gloryhack (Deacon) on Dec 19, 2005 at 20:38 UTC | |
| |
by Fletch (Bishop) on Dec 19, 2005 at 16:41 UTC |