#!/usr/bin/perl -wT

use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser); 

my $files_location; 
my $ID; 
my @fileholder;


$ID = param('ID');
if ($ID eq "1") { $filepath="/home/mark/public_html/forms"; $file="APPLICATION_FOR_ADMISSION_TO_THE_SCHOOL.doc"; }
if ($ID eq "2") { $filepath="/home/mark/public_html/forms"; $file="FEE_SCHEDULE_2013.xlsx"; }
if ($ID eq "3") { $filepath="/home/mark/public_html/forms"; $file="AFTERCARE_APPLICATION_FORM.doc"; }
if ($ID eq "4") { $filepath="/home/mark/public_html/forms"; $file="AFTERCARE_FEES_2008.doc"; }

if ($ID eq '') { 
print "Content-type: text/html\n\n"; 
print "You must specify a file to download."; 
} else {

open(DLFILE, "<$filepath/$file") || Error('open', 'file'); 
@fileholder = <DLFILE>; 
close (DLFILE) || Error ('close', 'file'); 


print "Content-Type:application/x-download\n"; 
print "Content-Disposition:attachment;filename=$file\n\n";
print @fileholder
}

sub Error {
      print "Content-type: text/html\n\n";
	print "The server can't $_[0] the $_[1]: $! \n";
	exit;
}
