Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Loading .PDFs

Loading .PDFs

Loading .PDFs

Not sure if this is the correct forum for this question.  Through my website, I need to allow a user to enter a number and open a corresponding .pdf.  The .pdf name looks like 'TR-0433 72689 to 72864' and the user can enter a number anywhere between 72689 amd 72864.  Can anyone direct me to a best method.  I'm using Dreamweaver to create the website.  Thank you in advance.

RE: Loading .PDFs

  • Which programming languages are supported on your server ?
  • Which programming languages you know ?
For example this could be one way of solving it with a bash CGI script :

CODE --> HTML ( fragment )

<form action="/cgi-bin/givemefile.sh">
File number : <input type="text" name="number">
<input type="submit" value="Give me that file">

CODE --> /cgi-bin/givemefile.sh"


fileprefix='TR-0433 '

[[ "$QUERY_STRING" =~ number=([[:digit:]]{5}) ]] && number="${BASH_REMATCH[1]}" || number='


[[ ! "$number" || "$number" -lt "$minnumber" || "$number" -gt "$maxnumber" || ! -f "$name" ]] && {
  echo $'Content-type: text/plain\r\n\r'
  echo "Invalid file number requested"

echo -e "Content-type: application/octet-stream\r
Content-disposition: attachment; filename=\"$name\"\r

cat "$name"
Requires bash version 4.0.0 or newer. Tested on  Linux with Apache web server.


RE: Loading .PDFs

CGI is definitely supported and .Net might also be available.  I'm new to web development.  Thank you for your help.

RE: Loading .PDFs


Quote (Feherke):

Which programming languages are supported on your server ?

Quote (LAM986):

CGI is definitely supported
Note that CGI is not a language.

Quote (Common Gateway Interface):

The Common Gateway Interface (CGI) is a standard protocol that defines how webserver software can delegate the generation of [link ]webpages[/link] to a console application. Such applications are known as CGI scripts; they can be written in any programming language, although scripting languages are often used.
( See the whole Common Gateway Interface article on Wikipedia. )

So my question is not answered yet.


RE: Loading .PDFs

Okay, thanks for the CGI information.  I have a better understanding.  The languages the host supports is PHP and Perl.  They have Linux servers.  Does this help?

RE: Loading .PDFs


Quote (LAM986):

The languages the host supports is PHP and Perl.
  • Hosts usually not allow shell scripts as CGI, for security reasons. So probably you can not use my previous code.
  • If you decide to use PHP and you have further questions, please post them in forum434: PHP.
  • If you decide to use Perl, we can continue in this forum, or in forum219: Perl.
To help your decision, here are the PHP and Perl rewrites of the Bash script :

CODE --> givemefile.php


$fileprefix='TR-0433 ';

if (is_numeric($_GET['number'])) $number=$_GET['number']; else $number=';


if (! $number || $number<$minnumber || $number>$maxnumber || ! file_exists($name)) {
  header('Content-type: text/plain');
  echo 'Invalid file number requested';

header('Content-type: application/octet-stream');
header("Content-disposition: attachment; filename=\"$fileprefix$number$filesuffix\"");


CODE --> givemefile.pl

#!/usr/bin/perl -w

$fileprefix='TR-0433 ';

if ($ENV{'QUERY_STRING'}=~/number=([[:digit:]]{5})/) { $number=$1 } else { $number=' }


if (! $number || $number<$minnumber || $number>$maxnumber || ! -f $name) {
  print "Content-type: text/plain\r\n\r\n";
  print 'Invalid file number requested';

print "Content-type: application/octet-stream\r
Content-disposition: attachment; filename=\"$fileprefix$number$filesuffix\"\r

open FIL,"<$name";
print while (<FIL>);
close FIL;
Note that I do not really like the CGI Perl module, so I avoid it for simple tasks like this. In forum219: Perl you will be firmly guided towards the use of CGI module. If you decide to use Perl, make sure you know their points of view too.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close