And a public web interface (debian server running apache2) that gets those records from the db (this time using DBD::Sybase for the db connection) and displays to the website inside an <img> tag:open(frontFILE, $imageFront.'.gif'); read (frontFILE, $blobFront, -s "$imageFront"); close frontFILE; open(backFILE, $imageBack.'.gif'); read (backFILE, $blobBack, -s "$imageBack"); close backFILE; my $sth=$db->prepare("Insert INTO docs (FrontImg,BackImg,docID) va +lues (?,?,?); $sth->execute($blobFront, $blobBack, $docID) or die $sth->errstr;
When I compare the output of $blob vs. $data->{BackImg}, $data->{BackImg} looks like a hex string with a length exactly double the length of $blob. $blob starts with 'GIF 89a' followed by what looks like gibberish. I'm not sure if the problem exists in inserting the image to the db, retrieving the image from the db or outputting to the webpage.my $whichImage = 'e5c59e0d-fc0e-4d8e-9fa5-7b3bac6f8f25'; #getting the image from the db my $db=DBI->connect('DBI:Sybase:server='.$server,$sql_user,$sq +l_password); $db->do("use ".$database) ; my $statement = "select FrontImg, BackImg, docid from docs whe +re docid = '$whichImage'"; my @rows=@{$db->selectall_arrayref($statement, {Slice => {}})} + ; unless( @rows){die "$statement \ndidn't find the image ".@rows +;} #there should only be one record returned -- docid is the prim +ary key my $data = $rows[0]; #to get the same image from file instead of the db: open FILE, "<$filebase".'/1001-1-B.gif' ; my $blob; read(FILE, $blob, -s $Lockbox::Web::CONFIG{filebase}.'/1001-1- +B.gif'); close FILE; #the following line displays only the dreaded empty box w/a red 'x +' #instead of the image from the database print $q->header(type=>'image/gif', Content_Length=>length($data-> +{BackImg})).$data->{BackImg} ; #the following line displays the image from the file correctly #but i need to get it from the db instead #print $q->header(type=>'image/gif', Content_Length=>length($blob) +).$blob ; if($blob ne $data->{BackImg}){die $data->{BackImg}."\nlength=" +.length($data->{BackImg})."\nfile image = ".$blob."\nlength=".length( +$blob);}
I tried playing with hex conversion, but all I ended up with was an empty string.
Any help would be appreciated...thanksksublondie
ps -- BTW...the original images (all 170,000+!) exist as tif's that I'm converting to gif's (so I can display inside the browser) using ImageMagick. If there's a more efficient way to do this, I'd appreciate the input.In reply to insert & retrieve images from DB to web by ksublondie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |