You need 2 scripts, e.g. pdf_index.cgi and pdf_display.cgi. The index page creates the links to the other cgi with an id parameter (assuming it is unique) to determine the pdf. This example puts the links in a table with the other fields.
#!perl use strict; use CGI qw(:standard); use DBI; my $dbh = get_dbh(); # html page print header,start_html; my $sql = 'SELECT id,name,description,vers FROM software_repos'; my $sth = $dbh->prepare($sql); $sth->execute(); print q!<table border="1" cellspacing="0" cellpadding="3"> <tr> <td>ID</td> <td>Name</td> <td>Description</td> <td>Version</td> <td>PDF</td> </tr>!; while (my @f = $sth->fetchrow_array()){ print qq!<tr> <td>$f[0]</td> <td>$f[1]</td> <td>$f[2]</td> <td>$f[3]</td> <td><a href="pdf_display.cgi?id=$f[0]" target="_blank">pdf</a></td> </tr>\n!; } print q!</table>!; print end_html; # whatever you need to get a connection sub get_dbh{ my $database = ""; my $user = ""; my $pw = ""; my $dsn = "dbi:mysql:$database:localhost:3306"; my $dbh = DBI->connect($dsn, $user, $pw, { RaiseError => 1, AutoComm +it => 1 } ); return $dbh; }
The other script to display the pdf is relatively simple
#!perl use strict; use CGI qw(:standard); use DBI; my $id = param('id'); my $dbh = get_dbh(); my $sql = "SELECT bin FROM software_repos WHERE id=?"; my ($pdf) = $dbh->selectrow_array($sql,undef,$id); print header('application/pdf'), binmode(STDOUT); print $pdf; # whatever you need to get a connection sub get_dbh{}
poj

In reply to Re: How to read a stored file from database and show in browser by poj
in thread How to read a stored file from database and show in browser by ghosh123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.