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.

Screenshot of main statistics

Main statistics

Screenshot of detailed statistics

Detailed statistics for a chosen file

Installation

  1. Create a subdirectory in your /wp-content/plugins/ directory and extract the plugin there. The plugin subdirectory can be anything you like – I use simple-download-monitor, but the plugin should accept any name.

  2. Activate the plugin through the Plugins menu in WordPress.

  3. 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 of files/ means that Simple Download Monitor will only allow download of files in the /files directory 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 zip or jpg here. Do not EVER allow php extension, 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.

    Screenshot of plugin options

    Plugin options

  4. The last step involves editing the .htaccess file. The default .htaccess skips 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 .htaccess file so that downloads are passed through Simple Download Monitor.

    This is easy enough to do: Open your .htaccess file and locate line:

    RewriteCond %{REQUEST_FILENAME} !-f

    Add this line directly above it:

    RewriteRule ^(files/.*) /index.php?sdmon=$1 [L]

    (replace ‘files/’ with your download directory).

Downloads

Podobné příspěvky:

32 Responses to “Simple Download Monitor plugin”

  1. Diefe Diefe napsal:

    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

  2. pepak pepak napsal:

    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.

  3. pepak pepak napsal:

    Version 0.06 fixes the bug.

  4. Diefe Diefe napsal:

    Thanks, now it works.

  5. Forge Forge napsal:

    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

  6. pepak pepak napsal:

    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.

  7. Forge Forge napsal:

    Thanks a lot. I follow this ^_^

  8. Ricardo Ricardo napsal:

    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

  9. pepak pepak napsal:

    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.

  10. Ricardo Ricardo napsal:

    i posted on your forum…google translate altough not perfect does wonders….

  11. pepak pepak napsal:

    The forum should autodetect user’s language now. Supported are czech, slovak and english.

  12. pepak pepak napsal:

    Version 0.07 adds support for inline content, allowing you to monitor the number of downloads of e.g. images embedded in your pages.

  13. Chad Chad napsal:

    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!!!!

  14. pepak pepak napsal:

    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.

  15. Craig Craig napsal:

    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.

  16. pepak pepak napsal:

    Will do.

  17. Ricardo Ricardo napsal:

    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

  18. Marcelo Marcelo napsal:

    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

  19. pepak pepak napsal:

    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.

  20. pepak pepak napsal:

    Version 0.08 available.

  21. Marcelo Dior Marcelo Dior napsal:

    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?

  22. pepak pepak napsal:

    I have no idea how PowerPress works, or even what it does and where to get it.

  23. Angelo Mandato Angelo Mandato napsal:

    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

  24. pepak pepak napsal:

    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!

  25. pepak pepak napsal:

    Version 0.09 fixes the issues reported by Angelo. Thanks!

  26. esanstudio.net esanstudio.net napsal:

    Any shortcode given to apply into WP PAGE?

  27. pepak pepak napsal:

    What kind of shortcode do you mean?

  28. Kyle Kyle napsal:

    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

  29. pepak pepak napsal:

    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.

  30. pepak pepak napsal:

    Version 0.10 provides compatibility with PHP 4 and a belarussian translation by FatCow.

  31. rafu rafu napsal:

    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

  32. pepak pepak napsal:

    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 +Indexes I would turn it off – it can be a serious security hole in certain circumstances.

Leave a Reply

Themocracy iconWordPress Themes