Catalog Script: display.cgi

This CGI script gets called to display an image from the catalog, like this:

  <IMG SRC="/cgi-bin/display.cgi?catno=64-1751988">
  


#!/usr/local/bin/perl
# display.cgi
# Fetch picture of product from the database

use DBI;
use lib 'modules';
use Catalog;
use CGI 'header','param';
use strict;
use vars '$DB';
use constant DB           => 'dbi:mysql:perl_conference';

no_content() unless my $catno = param('catno');

# open database
$DB = DBI->connect(DB,undef,undef,{PrintError=>0}) || die $DBI::errstr;


my $catalog = Catalog->new($DB) || die;
no_content() unless my $image = $catalog->image($catno);

print header(-type           => 'image/jpeg',
	     -content_length => length($image));
print $image;

$DB->disconnect;

sub no_content {
    print header(-status=>204);
    $DB->disconnect if defined $DB;
    exit 0;
}
  
<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Sun Apr 25 15:15:10 EDT 1999