Switch layouts home | FAQ | | P1 | P2 | P3 | P4 | P5 |  | A1 | A2 | A3  | | B1

Customizable download

1. Create a copy or a link to PB. It may be either a hard link or a symbolic link depending on your preferences and settings of the web server. The name of the link can be anything as long as the web server is going to run it as a cgi script. For example, a3.cgi
ln ../cgi-bin/pb.pl ./a3.cgi    or
ln -sf ../cgi-bin/pb.pl ./a3.cgi

2. Create a project configuration file. The name should be cgi-script's name + ".pm". For a3.cgi this file should be ./a3.cgi.pm
use vars qw($dbh $sth);
$templatesdir="sampledir";
$Parameter{Page}="home"; 
$Template{home}="$templatesdir/a3-home.html";
$Template{download}="$templatesdir/a3-download";

sub a3_download
{
  my $file = "$templatesdir/a3-downloadsample.txt";
  my $fname = substr($file, rindex($file, '/')+1);
  my $s;
  $s = "";
  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)= stat($file);
  if(open(IN,"<$file") > 0)
  {
    read(IN, $s, $size);
    close(IN);
  }
  else
  {
    &CI_text_html;
  }
  $s=~s/<IP>/$ENV{REMOTE_ADDR}/;
  print "Content-Disposition: Attachment; filename=\"$fname\"\n"
  ."Content-length: "."$size"."\n\n"
  ."$s";
  exit;
}
1;

3. Create an html-template file, a3-home.html
<!%if $Parameter{func} eq "a3_download()"%><!%set a3_download()%><!%else%>
Customizable download
<br><br>
<a href="/PB/a3.cgi?Page=download">download</a>
<!%endif%>

4. Create a file to customize for download, a3-downloadsample.txt
This file is customized for IP <IP>

5. This web project is complete. Check it out:
/PB/a3.cgi


2002-03