Download links, without the source file

Now this “hiding the source file” may seem irreverent but it can definitely help you out when it comes to tracking your downloads, seeing who’s downloading them, and file management. These are essential for any web developer because you want all the content on your site to be tracked and analyzed (not just the site itself). SEO professionals can provide their clients ways to track their site efficiently but can they track the downloads too? CMS systems provide ways to do that but what about custom made sites or blogs (like wordpress)? How can site owners know if the downloads they post on their site are even an importance to the audience they try to attract?

The first goal is to start making the downloads.php file. Its pretty simple.
This is directly from http://us3.php.net/header

1
2
3
4
5
6
7
8
9
10
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
 
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
 
// The PDF source is in original.pdf
readfile('original.pdf');
?>

Pretty easy right? Its setting the page type to be a direct download to “downloaded.pdf” and readfile(); is showing the original path to the file. Already the source of your file is hidden. I prefer the sources to be hidden just for peace of mind. Lets see how we can track it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
// made up class
include("class.trackdownloads.php");
 
$download = new trackdownloads();
// some features you can add to your site
$download->get_host();
$download->add_one_to_number_of_downloads();
$download->check_for_refer_link();
$download->check_if_user_downloaded_file_more_than_once();
 
// We'll be outputting a PDF
header('Content-type: application/pdf');
 
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
 
// The PDF source is in original.pdf
readfile('original.pdf');
?>

As you see, there are numerous possibilities that you can do when you manually code your downloads rather than just uploading them to the FTP and giving out the direct link to whomever you need to give it out to. Anyone who wants me to create a working class please comment back with ideas in what the program should do.

Marketing your website with a rapper

I was initially going to write about it, but this blows me away.