Lassie Posted June 7, 2007 Share Posted June 7, 2007 I need to log when a customer downloads a purchase which could be multiple. My script is structured as follows:- First run through script read dir and create download links and display user can click link for download(s) If file selected Get the filename to be downloaded and download. increment download count compare with total files to be downloaded if equal, update db end session and exit. My problem is my counter is not accumulating the download count. Any guidance appreciated. if not equal files still avaialable for download # If a download has already been selected, #----------------------------------------- If ($_GET['file']){ # Get the filename to be downloaded #---------------------------------- $file = $_GET['file']; $file = stripslashes($file); $file = htmlspecialchars($file); $mainpath = "$path$file"; # Increment download count #------------------------- $filename = "./file_info/descriptions/$file.0"; $newfile = fopen($filename,"r"); $content = fread($newfile, filesize($filename)); fclose($newfile); $fileinfo = explode ("|",$content); $fileinfo[0] ++; # Save the new file count #------------------------ $content = implode("|", $fileinfo); $newfile = fopen($filename,"w"); fwrite($newfile, $content); fclose($newfile); # Translate file name properly for Internet Explorer #--------------------------------------------------- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){ $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); } # Make sure the file exists before sending headers #------------------------------------------------- if(!$fdl=@fopen($mainpath,'rb')){ die("Cannot Open File!"); } else { ini_set("zlib.output_compression", "Off"); # Send the headers then send the file #------------------------------------ header("Cache-Control: ");# leave blank to avoid IE errors header("Pragma: ");# leave blank to avoid IE errors header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$file."\""); header("Content-length:".(string)(filesize($mainpath))); sleep(1); fpassthru($fdl); $counter++; #this for debug purpose $to="@yahoo.co.uk"; $subject="counter count"; $msg="all files downloaded for folder $hash and counter equals $counter and files equals $_SESSION[num] and "; mail($to,$subject,$msg); if ($counter==$_SESSION[num]) { #this is where db code will go $to="@yahoo.co.uk"; $subject="download count"; $msg="all files downloaded for folder $hash"; mail($to,$subject,$msg); $counter=0; } } Quote Link to comment https://forums.phpfreaks.com/topic/54609-help-with-logging-download/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.