Simple Download Monitor plugin
Simple Download Monitor is my first attempt at creating a WordPress plugin. I wrote it because I wanted to monitor the number of downloads of my files without having to maintain any kind of database or making any special download links. I just wanted to upload a file to a designated directory using FTP, provide a direct link to it and once in a while check the number of downloads. And this is pretty much what Simple Download Monitor does, with some slight additions, such as recording referers and username of people who download my files.
Main statistics
Detailed statistics for a chosen file
Installation
-
Create a subdirectory in your
/wp-content/plugins/directory and extract the plugin there. The plugin subdirectory can be anything you like – I usesimple-download-monitor, but the plugin should accept any name. -
Activate the plugin through the Plugins menu in WordPress.
-
You will see a Simple Download Monitor item in your Settings menu. You can enter three options there:
-
Allowed directories. The plugin could potentially be a huge security hole because it could be used to download source files of your site (e.g.
config.php– you definitely don’t want to allow that!). This option restricts Simple Download Monitor to directories matching a regular expression. The default value offiles/means that Simple Download Monitor will only allow download of files in the/filesdirectory and its subdirectories. -
Allowed extensions. Much like Allowed directories, allowed extensions protect your site’s files from unwanted downloads. It is a regular expression too and it is recommended to only place „safe“ extensions such as
ziporjpghere. Do not EVER allowphpextension, either directly or through wildcard (such as.*– that is a BIG NO-NO!). -
Store detailed info. If this option is checked, detailed information about each download (such as referer, user’s IP address or name, and date of download) is stored. This could fill your database quickly if you have a well-visited site so you can turn detailed info off and only keep the number of downloads and the date of last download.
Plugin options
-
-
The last step involves editing the
.htaccessfile. The default.htaccessskips default WordPress processing for existing files, which means that direct-linked files would get downloaded directly, without Simple Download Monitor ever learning about it. You need to modify the.htaccessfile so that downloads are passed through Simple Download Monitor.This is easy enough to do: Open your
.htaccessfile and locate line:RewriteCond %{REQUEST_FILENAME} !-fAdd this line directly above it:
RewriteRule ^(files/.*) /index.php?sdmon=$1 [L]
(replace ‘files/’ with your download directory).
Downloads
- The newest version at WordPress.org
- Simple Download Monitor v0.11 (2010-01-24, 67 KB). Compatibility PHP 4. Belarussian translation by Antsar.
- Simple Download Monitor v0.09 (2010-01-10, 50 KB). Fixed incorrect header for file length. Support for resumed transfers.
- Simple Download Monitor v0.08 (2009-11-29, 48 KB). Support for deleting unwanted stats.
- Simple Download Monitor v0.07 (2009-11-24, 47 KB). Allows monitoring of inline content (e.g. show downloads of images embedded in your pages).
- Simple Download Monitor v0.06 (2009-10-29, 43 KB). Fix for a crash if no downloads were recorded.
- Simple Download Monitor v0.05 (2009-10-28, 43 KB). The first public version.

Hey pepak,
i’ve installed and activatet the plugin, updated the settings and the .httaccess, put some files in the directory and downloaded some of them.
But when i look at tools–>Simple Download Monitor there’s only this error-message:
Warning: Invalid argument supplied for foreach() in /www/htdocs/abc/xyz/wp-content/plugins/simple-download-monitor/simple-download-monitor.php on line 392
Can you tell me what’s wrong?
Thanks, Diefe
Hi Diefe,
it means that there are no downloads to display. It is, of course, a bug – the plugin should be able to deal with no-downloads state gracefully rather than crashing. It will be fixed as soon as I figure out how to modify my plugin at WordPress repository; meanwhile, just download any monitored file and the bug will disappear.
Version 0.06 fixes the bug.
Thanks, now it works.
Hello Pepak
Your plugin don’t work on my website.
I’ve change the htaccess and place file (zip) into directory named „fichiers“ (i’m french) in the root (/www/fichiers).
- Where the dir „fichiers“ can be place ?
- this is my lines in htaccess :
RewriteRule ^(fichiers/.*) /index.php?sdmon=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
Is it ok ?
Thanks
I suggest we continue this discussion in the forums which are more suitable for problem solving than comments under the posts. When/if we reach a solution, I will post it here for the benefit of other users.
Thanks a lot. I follow this ^_^
Hi Pepak!
I was trying Simple download manager and in some files it says „:)“ in User and theres no referer Data, what does it mean?
Ive tried to post in your forum but i cant understand the language to register
1) In the „User“ field Simple Download Monitor shows either a username (if the user is logged in to your website) or a nick (if he isn’t logged in but he posted a comment on your site and hasn’t cleared cookies yet). Referer data may or may not be available, that depends on the user’s browser.
2) As far as forum is concerned, you don’t need to register to post. I’ll see about adding some autodetection of user’s country to it to switch the forum language to english.
i posted on your forum…google translate altough not perfect does wonders….
The forum should autodetect user’s language now. Supported are czech, slovak and english.
Version 0.07 adds support for inline content, allowing you to monitor the number of downloads of e.g. images embedded in your pages.
Hi,
I love ur plugin but I have a couple questions. What constitutes as a file being downloaded? Does the link just have to be clicked or does a „save as“ download box have to appear? I ask b/c I have an mp3 file that plays on my site but I want people to be able to download it also. However, I don’t want the „streaming“ mp3 to count as a click. Does that make sense? Thanks!!!!
It depends on how your streaming is done. „Download“ is counted if a file is requested through your webserver. If a file is requested without involving the webserver, it is not counted as a download. So if your streaming server (whatever it is, flash or webserver module or anything) requests the file through
http://www.yourserver.com/files/music.mp3, it will be counted as a download; if, instead, it loads a local file/www/yourserver.com/public/www/files/music.mp3, it won’t be counted. It may be a good feature to add an optional argument that would prevent counting. I’ll think about that.Just what I was looking for. Brilliant and easy to set up. 1 suggestion though – a button to clear stats so I can remove any generated by testing and mis-configuration.
Will do.
Glad to see you thought about my suggestion, i just done a quick test before activating and it also works outside my blog, if i embed an image on someone else’s site it also works.
Good work, just the button missing now to clear results/stats
Don’t work, i has create the file , upload files.
I can’t config correct .htaccess
RewriteEngine On
RewriteRule ^(facul/.*) /index.php?sdmon=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Please go to the Support Forums, try the solutions suggested there (especially the test that the plugin itself works) and if they don’t work, describe your problem in greater detail.
Version 0.08 available.
Man, I loved your widget, but it conflicts with PowerPress. When PowerPress tries to go on my audio folder to retrieve information on the mp3s so it can insert it in a post, it gets back with the message „Error occurred obtaining media file size.“ Even if I input the mp3 file path via the enclosure Custom Field, the audio player shown in the post won’t retrieve any info, instead playing the mp3 file while presenting „connecting…“ message instead of the status bar and 0:00 instead of the total/remaining time.
The only way I could get PowerPress to work was deactivating Simple Download Monitor and deleting the command line from the .htaccess. Do you know of a way that the two widgets would work together without this conflict?
I have no idea how PowerPress works, or even what it does and where to get it.
First problem is your script is not including the „Content-Length“ header. I do see „Content-size’, but that is not a valid HTTP header. Typically the second world is Capitalized though most clients will handle content-length or Content-Length.
Second problem is with the protocol returned, you need to change the protocol to HTTP/1.0 or add support for range requests. PowerPress plugin requests the first 500KB of the file by using an HTTP „Range: 0-500000″ request. I just took a look at your plugin and it does not support byte ranges, which can create a problem for anyone who may want to resume downloads. It does not create a problem for PowerPress so as long as you change the returned HTTP Headers return HTTP/1.0 (rather than HTTP/1.1). You can detect and appropriately handle a byte range request with the following: isset($_SERVER['HTTP_RANGE']) and parse it to know what portion of the file to return.
Please refer to the RFC (http://www.faqs.org/rfcs/rfc2616.html) for HTTP to learn more about ‘Content-Length’ and ‘Byte Ranges’. This page has an example how to handle multiple and single byte range requests in PHP: http://www.coneural.org/florian/papers/04_byteserving.php
1) If I use content-size, it is an error – content-length is the correct one. I will check it out and correct it. Thanks for the alert.
2) I didn’t know about that. I will see about adding range support to SDM (it would be easier to use HTTP/1.0, but I expect range support will allow the users to continue broken transfers).
Thanks!
Version 0.09 fixes the issues reported by Angelo. Thanks!
Any shortcode given to apply into WP PAGE?
What kind of shortcode do you mean?
when i install this plugin, both manually or threw wordpress, i get this error message opon activation: Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /ndd5/wp-content/plugins/simple-download-monitor/simple-download-monitor.php on line 34
It seems your hosting doesn’t use PHP 5. While it would be possible to rewrite SDM to work with PHP 4, I have no way of testing it.
Version 0.10 provides compatibility with PHP 4 and a belarussian translation by FatCow.
i have installed the plugins and didnt worked well i check my .htaccess file didnt got any line writen that called RewriteCond %{REQUEST_FILENAME} !-f
it’s just writen
Options +Indexes
# BEGIN WordPress
# END WordPress
PLEASE TEL ME WHATS SHOULD I DO
I am afraid there is little I can do to help you. Apparently your WordPress is set up without mod_rewrite. It may be that it is not supported by your webhost, in which case there is nothing you can do to make Simple Download Manager work. Alternatively, it is possible that mod_rewrite is supported but isn’t used – in that case you can try to place this in your .htaccess file:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^(files/.*) /index.php?sdmon=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>Note: Unless you are really sure you want to have
Options +IndexesI would turn it off – it can be a serious security hole in certain circumstances.