D
dbmeyers23
All,
I'm trying to create a "simple" web-based application that will allow
users to search for pdf files, and when the files exist, the browser
opens the .pdf in the browser. I can get the form to find the .pdf
and open it on a PC, but the filename is still the name of the ".cgi"
script.
I also cannot get my basic version to work on the Macintosh platform.
I've scoured the web for answers, and have pieced together some code
from different sources, but I'm missing two crucial pieces....having
the file show up with the real name (not script.cgi) and getting this
to work on Macintosh OS9 browsers(file is corrupted).
Here's my code:
#!/usr/bin/perl -wT
###########################Find pdf ads based on user submission
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $files_location;
my $ID;
my @fileholder;
$files_location = "/usr/local/apache2/pdfads";
$ID = param('pdfname');
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.<br>";
print "<br>";
print "<form name=pdf method=post action=../cgi-bin/download.cgi>";
print "New pdf search<br>";
print "<br>";
print "<table>";
print "<tr><td><b>Ad Number:</b><input type=text maxlength=30
name=pdfname size=20></td></tr>";
print "</table>";
print "<input type=submit name=Submit value=View PDF size=15>";
print "</form>";
exit;
}
if (-e "$files_location/$ID")
{
open(DLFILE, "<$files_location/$ID") || die ("Cannot open PDF ad $ID,
try again.<br>");
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
###print "Content-Type:application/x-download\n";
print "Content-Type:application/pdf\n";
print "Content-Disposition:inline; filename=$ID\n\n";
print @fileholder
}
print "Content-type: text/html\n\n";
print "Cannot find PDF Ad $ID, please try again<br>";
print "<form name=pdf method=post action=../cgi-bin/download.cgi>";
print "<br>";
print "<table>";
print "<tr><td><b>Ad Number:</b><input type=text maxlength=30
name=pdfname size=20></td></tr>";
print "</table>";
print "<input type=submit name=Submit value=View PDF size=15>";
print "</form>";
exit;
I'm trying to create a "simple" web-based application that will allow
users to search for pdf files, and when the files exist, the browser
opens the .pdf in the browser. I can get the form to find the .pdf
and open it on a PC, but the filename is still the name of the ".cgi"
script.
I also cannot get my basic version to work on the Macintosh platform.
I've scoured the web for answers, and have pieced together some code
from different sources, but I'm missing two crucial pieces....having
the file show up with the real name (not script.cgi) and getting this
to work on Macintosh OS9 browsers(file is corrupted).
Here's my code:
#!/usr/bin/perl -wT
###########################Find pdf ads based on user submission
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $files_location;
my $ID;
my @fileholder;
$files_location = "/usr/local/apache2/pdfads";
$ID = param('pdfname');
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.<br>";
print "<br>";
print "<form name=pdf method=post action=../cgi-bin/download.cgi>";
print "New pdf search<br>";
print "<br>";
print "<table>";
print "<tr><td><b>Ad Number:</b><input type=text maxlength=30
name=pdfname size=20></td></tr>";
print "</table>";
print "<input type=submit name=Submit value=View PDF size=15>";
print "</form>";
exit;
}
if (-e "$files_location/$ID")
{
open(DLFILE, "<$files_location/$ID") || die ("Cannot open PDF ad $ID,
try again.<br>");
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
###print "Content-Type:application/x-download\n";
print "Content-Type:application/pdf\n";
print "Content-Disposition:inline; filename=$ID\n\n";
print @fileholder
}
print "Content-type: text/html\n\n";
print "Cannot find PDF Ad $ID, please try again<br>";
print "<form name=pdf method=post action=../cgi-bin/download.cgi>";
print "<br>";
print "<table>";
print "<tr><td><b>Ad Number:</b><input type=text maxlength=30
name=pdfname size=20></td></tr>";
print "</table>";
print "<input type=submit name=Submit value=View PDF size=15>";
print "</form>";
exit;