code-tutorial.com

The best resources for developers

How can you track a downloaded file?

$filename = base64_url_decode($_REQUEST["file"]);
header("Cache-Control: public");
header("Content-disposition: attachment; filename=".basename($filename));
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". filesize($filename));

//  Put either file counting code here, either a db or static files
//
readfile($filename);  //and spit the user the file

function base64_url_decode($input) {
    return base64_decode(strtr($input, "-_,", "+/="));
}
function base64_url_encode($input) {
     return strtr(base64_encode($input), "+/=", "-_,");
}

Tags: php apache logging analytics download

Source: By Grant as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0


Related code-snippets: