PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Loren Delamarter <ldelamar at north-pacific dot com>
Subject: Re: BLOBs
Date: Sep 24 1997 7:26PM

Here's my little imageFetch cgi script which has been working for
quite a while for retrieving Adobe Acrobat PDF files. It should work
for any type of binary object including GIFs etc. You would just
change the "Content-type: application/pdf\n\n" line to your type.

The other thing is that you should probably "binmode(STDOUT);"
to make the script work for graphics. I think I'm just getting lucky
with the PDFs so far. I'll have to test that later. Anyway here it is:

#!/usr/local/bin/perl
 
$debug      = 0;
$SERVER     = 'SERVERNAME';
$DATABASE   = 'your_db';
$USER       = 'your_user';
$PASSWD     = 'your_pw';
$TABLE      = 'tb_yourTable';
$PROGNAME   = 'imageFetch';

$TEXTSIZE   = '200000';		# this is important!
 
if ($ARGV[0] eq "" ) {
        print "Content-type: text/plain\n\n";
        print "$PROGNAME: No imageNum parameter passed.
"; exit 1; } $imageNum = $ARGV[0]; # image in column called "imageData" $|=1; use Sybase::DBlib; $dbh = new Sybase::DBlib $USER, $PASSWD, $SERVER, "$PROGNAME"; $sql = "select imageData from $DATABASE..$TABLE where imageNum = $imageNum"; $dbh->dbcmd("set textsize $TEXTSIZE"); $dbh->dbsqlexec; $dbh->dbcmd("$sql"); $dbh->dbsqlexec; $dbh->dbresults; @results = $dbh->dbnextrow; # Sometimes it's easier to debug by writing to file if ( $debug ) { $BIN_FILE = "/tmp/img.$imageNum"; open(BIN_FILE,">$BIN_FILE") || die "Couldn't open $BIN_FILE:$!\n"; binmode(BIN_FILE); } print "Content-type: application/pdf\n\n"; foreach(@results) { print BIN_FILE if $debug; # debug write to file print STDOUT; # print to STDOUT } close(BIN_FILE) if $debug; $dbh->dbclose; exit;