I have recently downloaded a download counter from focal media.
I have installed onto a unix server and tested in both mac and pc environments.
Works great on pc, but if I download a file from a mac, each download counts as 2.
Code below. Any ideas appreciated
if ($ENV{'QUERY_STRING'} ne "") {
$temp = $ENV{'QUERY_STRING'};
}
else
{
read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
}
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
$fields{'comment'}=~s/\cM//g;
$fields{'comment'}=~s/\n\n/<p>/g;
$fields{'comment'}=~s/\n/<br>/g;
$fields{'download'} =~ s/\;//g;
$fields{'download'} =~ s/^\s+//g;
$fields{'download'} =~ s/\s+$//g;
############################################################
############################################################
############################################################
############################################################
### ERROR CHECKING
$file_exists = (-e "$download_loc/$fields{'download'}");
if ($file_exists < 1)
{
&file_not_exist;
exit;
}
### OPERATIONS
#print "Content-type: text/html\n\n";
$exists1 = (-e "$data_dir/index.idx");
if ($exists1 > 0)
{
open (DNL, "$data_dir/index.idx");
while (defined($line=<DNL>))
{
####### filename, Number of Downloads
($filename, $counter, $tmp) = split (/:-:/,$line, 3);
#print "$filename __ $counter __ $tmp <br>";
if ($filename eq "$fields{'download'}")
{
$counter++;
$towrite = $towrite . $filename . ":-:" . $counter . ":-:" . "\n";
$written = "true";
}
else
{
$towrite = $towrite . "$line"; #. "\n";
}
}
close (DNL);
if ($written ne "true")
{
open (DNL, ">> $data_dir/index.idx");
print DNL $fields{'download'} . ":-:" . "1" . ":-:" . "\n";
close (DNL);
}
else
{
open (DNL, "> $data_dir/index.idx");
print DNL $towrite;
close (DNL);
}
}
else
{
$counter = 1;
if ($written ne "true")
{
open (DNL, "> $data_dir/index.idx");
print DNL $fields{'download'} . ":-:" . "1" . ":-:" . "\n";
close (DNL);
}
}
##### RECORD INFO
$rfile = $fields{'download'};
$fields{'download'} =~ tr/./_/;
$fields{'download'} = $fields{'download'} . ".txt";
$ip_address = $ENV{'REMOTE_ADDR'};
$browser = $ENV{'HTTP_USER_AGENT'};
($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime();
$mon++;
$year = 1900 + $year;
$today = $year . "-" . $mon . "-" . $mday . " " . $hour . ":" . $min . ":" . $sec;
open (DLD, ">> $data_dir/$fields{'download'}");
######### WEBURL HEAR OF NAME
print DLD $fields{'weburl'} . ":-:" . $fields{'where'} . ":-:" . $fields{'name'} . ":-:" .
#EMAIL MAILING LIST IP
$fields{'email'} . ":-:" . $fields{'ml'} . ":-:" . $ip_address . ":-:" . $browser . ":-:" .
#TODAY
$today . ":-:\n";
close (DLD);
print "Location: $download_files/$rfile\n\n";
exit;
sub file_not_exist
{
print "Content-type: text/html\n\n";
print <<End_of_nexist;
<html>
<head>
<title>File Not Found</title>
</head>
<body>
<p> </p>
<p> </p>
<p> </p>
<div align="center"><center>
<table border="0" cellspacing="0" cellpadding="0" width="400">
<tr>
<td bgcolor="#000000"><table border="0" cellspacing="1" width="100%" cellpadding="6">
<tr>
<td width="100%" bgcolor="#FFCC00" valign="top"><p align="center"><font face="Verdana"
size="2"><b>404 File Not Found</b></font></td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF" valign="top"><font face="Verdana" size="2"><b></b>
<br>
The file you requested could not be found. Please use the back button of your browser to
go back.<br>
<b></b></font></td>
</tr>
</table>
</td>
</tr>
</table>
</center></div>
</body>
</html>
End_of_nexist
}
I have installed onto a unix server and tested in both mac and pc environments.
Works great on pc, but if I download a file from a mac, each download counts as 2.
Code below. Any ideas appreciated
Code:
if ($ENV{'QUERY_STRING'} ne "") {
$temp = $ENV{'QUERY_STRING'};
}
else
{
read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
}
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
$fields{'comment'}=~s/\cM//g;
$fields{'comment'}=~s/\n\n/<p>/g;
$fields{'comment'}=~s/\n/<br>/g;
$fields{'download'} =~ s/\;//g;
$fields{'download'} =~ s/^\s+//g;
$fields{'download'} =~ s/\s+$//g;
############################################################
############################################################
############################################################
############################################################
### ERROR CHECKING
$file_exists = (-e "$download_loc/$fields{'download'}");
if ($file_exists < 1)
{
&file_not_exist;
exit;
}
### OPERATIONS
#print "Content-type: text/html\n\n";
$exists1 = (-e "$data_dir/index.idx");
if ($exists1 > 0)
{
open (DNL, "$data_dir/index.idx");
while (defined($line=<DNL>))
{
####### filename, Number of Downloads
($filename, $counter, $tmp) = split (/:-:/,$line, 3);
#print "$filename __ $counter __ $tmp <br>";
if ($filename eq "$fields{'download'}")
{
$counter++;
$towrite = $towrite . $filename . ":-:" . $counter . ":-:" . "\n";
$written = "true";
}
else
{
$towrite = $towrite . "$line"; #. "\n";
}
}
close (DNL);
if ($written ne "true")
{
open (DNL, ">> $data_dir/index.idx");
print DNL $fields{'download'} . ":-:" . "1" . ":-:" . "\n";
close (DNL);
}
else
{
open (DNL, "> $data_dir/index.idx");
print DNL $towrite;
close (DNL);
}
}
else
{
$counter = 1;
if ($written ne "true")
{
open (DNL, "> $data_dir/index.idx");
print DNL $fields{'download'} . ":-:" . "1" . ":-:" . "\n";
close (DNL);
}
}
##### RECORD INFO
$rfile = $fields{'download'};
$fields{'download'} =~ tr/./_/;
$fields{'download'} = $fields{'download'} . ".txt";
$ip_address = $ENV{'REMOTE_ADDR'};
$browser = $ENV{'HTTP_USER_AGENT'};
($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime();
$mon++;
$year = 1900 + $year;
$today = $year . "-" . $mon . "-" . $mday . " " . $hour . ":" . $min . ":" . $sec;
open (DLD, ">> $data_dir/$fields{'download'}");
######### WEBURL HEAR OF NAME
print DLD $fields{'weburl'} . ":-:" . $fields{'where'} . ":-:" . $fields{'name'} . ":-:" .
#EMAIL MAILING LIST IP
$fields{'email'} . ":-:" . $fields{'ml'} . ":-:" . $ip_address . ":-:" . $browser . ":-:" .
#TODAY
$today . ":-:\n";
close (DLD);
print "Location: $download_files/$rfile\n\n";
exit;
sub file_not_exist
{
print "Content-type: text/html\n\n";
print <<End_of_nexist;
<html>
<head>
<title>File Not Found</title>
</head>
<body>
<p> </p>
<p> </p>
<p> </p>
<div align="center"><center>
<table border="0" cellspacing="0" cellpadding="0" width="400">
<tr>
<td bgcolor="#000000"><table border="0" cellspacing="1" width="100%" cellpadding="6">
<tr>
<td width="100%" bgcolor="#FFCC00" valign="top"><p align="center"><font face="Verdana"
size="2"><b>404 File Not Found</b></font></td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF" valign="top"><font face="Verdana" size="2"><b></b>
<br>
The file you requested could not be found. Please use the back button of your browser to
go back.<br>
<b></b></font></td>
</tr>
</table>
</td>
</tr>
</table>
</center></div>
</body>
</html>
End_of_nexist
}