Loading .PDFs
Loading .PDFs
(OP)
Hello,
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.
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 )
File number : <input type="text" name="number">
<input type="submit" value="Give me that file">
</form>
CODE --> /cgi-bin/givemefile.sh"
minnumber='72689'
maxnumber='72864'
pdfdirectory='.'
fileprefix='TR-0433 '
filesuffix='.pdf'
[[ "$QUERY_STRING" =~ number=([[:digit:]]{5}) ]] && number="${BASH_REMATCH[1]}" || number='
name="$pdfdirectory/$fileprefix$number$filesuffix"
[[ ! "$number" || "$number" -lt "$minnumber" || "$number" -gt "$maxnumber" || ! -f "$name" ]] && {
echo $'Content-type: text/plain\r\n\r'
echo "Invalid file number requested"
exit
}
echo -e "Content-type: application/octet-stream\r
Content-disposition: attachment; filename=\"$name\"\r
\r"
cat "$name"
Feherke.
http://free.rootshell.be/~feherke/
RE: Loading .PDFs
RE: Loading .PDFs
Note that CGI is not a language.
( See the whole Common Gateway Interface article on Wikipedia. )
So my question is not answered yet.
Feherke.
http://free.rootshell.be/~feherke/
RE: Loading .PDFs
RE: Loading .PDFs
- 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
$minnumber=72689;
$maxnumber=72864;
$pdfdirectory='.';
$fileprefix='TR-0433 ';
$filesuffix='.pdf';
if (is_numeric($_GET['number'])) $number=$_GET['number']; else $number=';
$name="$pdfdirectory/$fileprefix$number$filesuffix";
if (! $number || $number<$minnumber || $number>$maxnumber || ! file_exists($name)) {
header('Content-type: text/plain');
echo 'Invalid file number requested';
exit;
}
header('Content-type: application/octet-stream');
header("Content-disposition: attachment; filename=\"$fileprefix$number$filesuffix\"");
readfile($name);
CODE --> givemefile.pl
$minnumber=72689;
$maxnumber=72864;
$pdfdirectory='.';
$fileprefix='TR-0433 ';
$filesuffix='.pdf';
if ($ENV{'QUERY_STRING'}=~/number=([[:digit:]]{5})/) { $number=$1 } else { $number=' }
$name="$pdfdirectory/$fileprefix$number$filesuffix";
if (! $number || $number<$minnumber || $number>$maxnumber || ! -f $name) {
print "Content-type: text/plain\r\n\r\n";
print 'Invalid file number requested';
exit;
}
print "Content-type: application/octet-stream\r
Content-disposition: attachment; filename=\"$fileprefix$number$filesuffix\"\r
\r\n";
open FIL,"<$name";
print while (<FIL>);
close FIL;
Feherke.
http://free.rootshell.be/~feherke/