b310 has asked for the wisdom of the Perl Monks concerning the following question:
I have two images in a database that I would like to display on a web page.
When I run my script, the column that should have the image displays a "1". I do not understand why that is happening.
The first batch of code is a script that should be the link for the image. This has worked in a prior script for me.
The second batch of code is where I'm calling the link to display the image:#!/usr/bin/perl -Tw # serve_image.cgi - serve an image file as a Web page use CGI qw(:standard escape escapeHTML); use DBI; use strict; use CGI::Carp qw(fatalsToBrowser); use lib qw(/usr50/home/summitwe/public_html/library); use WebDB; #@ DISPATCH if (defined (param ("item_id"))) { display_image (param ("item_id"), param ("thumbnail")); } elsif (defined (param ("gallery"))) { display_gallery () } else { error ("Unknown request type"); } #@ DISPATCH exit (0); #@ DISPLAY_IMAGE sub display_image { my ($item_id, $show_thumbnail) = @_; my $col_name = (defined ($show_thumbnail) ? "thumbnail" : "picture"); my ($dbh, $mime_type, $data); $dbh = WebDB::connect (); ($mime_type, $data) = $dbh->selectrow_array ( "SELECT mime_type, $col_name FROM catalog_pet WHER +E item_id = ?", undef, $item_id); $dbh->disconnect (); # did we find a record? error ("Cannot find image named $item_id") unless defined ($mime_t +ype); print header (-type => $mime_type, -Content_Length => length ($dat +a)), $data; } #@ DISPLAY_IMAGE # Present gallery of names and images in the image table. Present the # thumbnail version of each image, but embed the image inside a hyperl +ink # that selects the full size image for display. #@ DISPLAY_GALLERY sub display_gallery { my ($dbh, $sth); print header (), start_html ("Image Gallery"); $dbh = WebDB::connect (); $sth = $dbh->prepare ("SELECT item_id FROM catalog_pet ORDER BY it +em_id"); $sth->execute (); # we're fetching a single value (name), so we can call fetchrow_ar +ray() # in a scalar context to get the value while (my $item_id = $sth->fetchrow_array ()) { # encode the name with escape() for the URL, with escapeHTML() + otherwise my $url = url () . sprintf ("?item_id=%s", escape ($item_id)); $item_id = escapeHTML ($item_id); print p ($item_id), a ({-href => $url}, # link for full size image # embed thumbnail as the link content to make it click +able img ({-src => "$url;thumbnail", -alt => $item_id}) ), "\n"; } $sth->finish (); $dbh->disconnect (); print end_html (); } #@ DISPLAY_GALLERY #@ ERROR sub error { my $msg = shift; print header (), start_html ("Error"), p (escapeHTML ($msg)), end_html (); exit (0); } #@ ERROR
sub get_product_table { my $sth = shift; my @row; while (my $ref = $sth->fetchrow_hashref ()) { my $serve_url = sprintf ("serve_image.cgi?item_id=%s;thumbnail", +escape ($ref->{item_id})); # generate a form allowing a quantity of the item to be added # to the cart push (@row, start_form(-method=>'GET', -action=>url()), hidden( -name => "choice", -override => 1, -default => "add" ), hidden( -name => "item_id", -override => 1, -default => escapeHTML( $ref->{item_id} )), Tr ( td (print img ({-src => $serve_url, -alt => escapeHTML($ref->{item_ +id})})),
I want to display the thumbnail version of the image. As I mentioned, when I run my script, the column that should print the image, prints a "1" instead.
I can really use some help. I've been at this for a while now, and I'm not sure what to do.
Thanks.
update (broquaint): added <readmore> and formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Displaying Images using Perl
by poj (Abbot) on Jan 28, 2003 at 20:45 UTC | |
by b310 (Scribe) on Jan 28, 2003 at 20:55 UTC | |
|
Re: Displaying Images using Perl
by steves (Curate) on Jan 28, 2003 at 20:23 UTC | |
by b310 (Scribe) on Jan 28, 2003 at 20:31 UTC | |
|
Re: Displaying Images using Perl
by LAI (Hermit) on Jan 28, 2003 at 20:51 UTC | |
|
Re: Displaying Images using Perl
by Gilimanjaro (Hermit) on Jan 28, 2003 at 20:57 UTC |