How can I Upload a document file in Wordpress and track its download?

109 Views Asked by At

I am creating my document-sharing site using wordpress. But I have problems when doing a Upload-file form and Download tracking. Of course I make it front-end. I want to ask you for help about how can I track the uploaded file --> To make "Popular Download Document" and make "Download History" in user's profile. Or could you help me something like that. Many thanks !

2

There are 2 best solutions below

2
On BEST ANSWER
$mysql_query = "UPDATE `download` SET `counter_download` = counter_download + 1";

// Execute your Query with your mysql or mysqli or pdo ...
// Then, let user download file with php function force_download().

force_download("/folder/file.zip");

Finally call your column where you insert download counter.

3
On

To get track of downloaded document, use one field in your database table named as num_downloads. See when you hit some download page like abc.com/downloads.php?id=10, now downloads.php will be your page and you have query string id=10. So for that product increment/update its num_downloads by one as soon as it gets hit. So 20 times Only i clicked on link, then count for that file will be +20 than original num_downloads count.

So roughly your table structure for say table files will be

id   name_of_file        num_downloads
1    harry potter book   100

Where num_downloads field will increment by one on each hit for particular file.