#!/usr/bin/perl

#open(INF,"datafiles/dlindex");
#$dlindex = <INF>;
#close(INF);

opendir (dir, "dlfiles42/");
@listdir = readdir dir;
close dir;
$dlindex = "dlfiles42";
@values = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) { ($name, $value) = split(/=/,$i); 
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/\n/ /g; # replace newlines with spaces
    $value =~ s/\r//g;  # remove hard returns
    $value =~ s/\cM//g; # delete ^M's
    $FORM{$name} = $value;
  }


$tod=localtime(time);
if (($ENV{'HTTP_REFERER'} ne "" ) && ($ENV{'HTTP_REFERER'} !~ /videohelp/g )) {
#open (OUTF, ">>datafiles/referrals");
#print OUTF $tod."|"."$ENV{'HTTP_REFERER'}\n";
#close (OUTF);
}
$testfile="";
foreach $w(@listdir) {
if ($w eq $FORM{d}) {
$testfile="true";
}
}
if ($testfile eq "true") {
open (INF,"logs/$FORM{d}");
$size = <INF>;
close (INF);
$size++;

open (OUT,">logs/$FORM{d}");
print OUT $size;
close (OUT);


print "Location:  $dlindex/$FORM{d}\n\n";

} else {
print "Content-type:text/html\n\n";
print "File does not exist";
}
