PHP flat file download counter

Johnny

New Member
I got this freely available php-script to track download statistics. Simple really, it just count downloads and pass it on to a log file and another script uses that log file to display a top 10 list. So it's exactly what I need so I would really like to make this script work. But it doesn't. Of course. I have limited knowledge in php (but have learned a lot since encountering this script!). According to the author, it has been tested on Apache- and php-versions similar to mine, without problems. So I have been hesitant to actually change any code. I have tried to chmod logfile and/or whole subdirectory to 666 and 777 with no success.My own poor detective work leads nowhere and I have really tried. So I resort to the one thing I usually never do, to ask for help.The link should have the form: \[code\]<a href=http://www.yoursite.com/downloader/download.php?number=1&file=filename.zip>\[/code\]download.php follows below:\[code\]$number = $_GET['number'];$file = $_GET['file'];$logfile = "ROOT DIRECTORY PATH/logfile.txt";$array[dir_1] = "URL PATH/DOWNLOADFILESFOLDER"; $download = "dir"."_"."$number"; if ($array[$download]) { $fp = fopen($logfile,'r'); while (!feof($fp)) { $data[] = chop(fgets($fp,4096)); } fclose($fp); $fp = fopen($logfile,"w"); if (flock($fp,LOCK_EX)) { // list and split each filename and number of downloads foreach ($data as $lines){ list($downloads,$filename,$realname) = split("\|",$lines); // check if file already exists and add one more download if it does if ($filename == $file){ $downloads++; } if ($filename <> ""){ fputs($fp,"$downloads|$filename|$realname\r\n"); } } flock($fp,LOCK_UN); } fclose($fp); header("Location: $array[$download]/$file");}\[/code\]However one part of the script doesn't make sense to me; where does it obtain the filename and the realname so it can be put into the logfile if the file never has been downloaded before? The list() function and the array of the directory boggles my mind a bit. Though it seems logical.If someone catches some fundamental error or have some tips on how I can continue, it would be highly appreciated.PS. I am trying to track pdf-files if that helps.UPDATE! By kind suggestion I ran error reporting and got an error. The faulty scripts had an error in it that I removed. I ran error checking again and only got "Notices" about undefined variables. I changed the error reporting to \[code\]error_reporting(E_ALL ^ E_NOTICE);\[/code\]After that, no errors at all.
 
Back
Top