Gossamer Forum
Home : General : Perl Programming :

download counter not accurate on mac

Quote Reply
download counter not accurate on mac
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 Smile

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>&nbsp;</p>



<p>&nbsp;</p>



<p>&nbsp;</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>

&nbsp;&nbsp;&nbsp; <br>

The file you requested could not be found. Please use the back button of your browser to

go back.<br>

&nbsp;&nbsp;&nbsp; <b></b></font></td>

</tr>

</table>

</td>

</tr>

</table>

</center></div>

</body>

</html>



End_of_nexist



}
Subject Author Views Date
Thread download counter not accurate on mac fluffyduck 8574 Dec 1, 2003, 2:51 PM
Thread Re: [fluffyduck] download counter not accurate on mac
Andy 8336 Dec 2, 2003, 2:36 AM
Thread Re: [Andy] download counter not accurate on mac
Recall 8346 Dec 2, 2003, 9:28 AM
Thread Re: [Recall] download counter not accurate on mac
Andy 8331 Dec 2, 2003, 9:31 AM
Thread Re: [Andy] download counter not accurate on mac
Recall 8341 Dec 2, 2003, 10:28 AM
Thread Re: [Recall] download counter not accurate on mac
Andy 8308 Dec 2, 2003, 10:31 AM
Thread Re: [Andy] download counter not accurate on mac
Recall 8333 Dec 2, 2003, 10:33 AM
Thread Re: [Recall] download counter not accurate on mac
fluffyduck 8257 Dec 3, 2003, 2:46 PM
Post Re: [fluffyduck] download counter not accurate on mac
Recall 8242 Dec 3, 2003, 5:20 PM