Jump to content

Recommended Posts

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;	
}
  
}


 

 

Link to comment
https://forums.phpfreaks.com/topic/54609-help-with-logging-download/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.