Download Counter

Post Reply
User avatar
stani
Master Bludit
Posts: 122
Joined: Wed Oct 14, 2020 1:34 pm
Has thanked: 6 times
Been thanked: 3 times

My Vibe Coding... ;)

In Czech, English, and German.

Installation
1. Unzip the archive and upload the `download-counter` folder to `bl-plugins/`.
2. Activate it in the admin panel under Settings → Plugins.
3. Insert a link to the uploaded file into your page using the editor (the path begins with `/bl-content/uploads/…`). No shortcode is required.
How it works
• When the site is viewed, the plugin rewrites links to attachments as `?dlcount=<file>`. This registers the download and redirects the user to the actual file.
• Download counts are stored in `bl-content/databases/download-counter/counts.php`. File locking prevents data loss during simultaneous access.
• The plugin settings display an overview of download counts for all files. You can also configure which file extensions to track, as well as the text displayed after the link (`%d` represents the count).
• By default, the plugin does not rewrite links to images—only to standard documents and archives. The list of extensions can be modified.
• Bots (identified via User-Agent) are not counted. Similarly, requests other than GET are excluded.
• Files are verified using `realpath`, ensuring that the parameter cannot be used to download files located outside the `uploads` directory. Only extensions included in the allowed list are permitted (meaning `.php` files are excluded).

Limitations
• Only links that pass through your website are counted. If someone includes a direct URL (e.g., `/bl-content/uploads/...`) in an email or on another website, the counter will not detect it. If necessary, you can block direct access via `.htaccess`.
• The count will appear for existing links as well, but it starts at 0. It is not possible to retroactively calculate previous downloads.
Attachments
download-counter.zip
(5.99 KiB) Downloaded 8 times
Post Reply