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:

69 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.

  33. palantium palantium napsal:

    SORRY MY PREVIOUS MESSAGE, I COPIED UNTRANSLATED.

    Hi,

    I made the plugin work properly but I have a small problem: change the name of your downloads.

    For example: Download „Chapter 1 – Article 2211.pdf“ the left „Chapter“, short everything that is going after the space.

    The problem is solved when I delete the htaccess modification.

    Any solution?

    Thanks in advance.

  34. pepak pepak napsal:

    I have never tried SDMon with filenames with space character in them. I will test it during the weekend.

  35. pepak pepak napsal:

    I have just tried a filename with spaces in it and it works fine for me. In order to find the cause of the problem, I will need more detailed information. Please go to my forum and either append to the existing threads or create a new one. You don’t need to register to post there. Once I know you are in the right place, we can try to find the solution to your problem.

  36. samontab samontab napsal:

    This is an excellent plug-in for wordpress. I only have two suggestions that will turn it into a perfect plug-in for me:

    1) Add a country flag for each IP. I think this would be easy to do. You only need an IP to country table (or web service) and some images. The images can be obtained from http://www.famfamfam.com/lab/icons/flags/ or a similar project. I am sure there are free solutions for the IP to country table as well.

    2) Merge multiple downloads from the same IP at almost the same time. Normally this plug-in works correctly but if you use a download manager like DownThemAll for instance, the browser requests the file more than one time to the server (for speeding up the download) so the download counter gets increased more than it should. A simple check of IP/time with a certain time threshold may solve this issue.

    Thank you very much for developing this plug-in, it is exactly what I was looking for. If you implement those two features, it would be perfect.

  37. pepak pepak napsal:

    1) I will need to look into available libraries and their implementation. I am somewhat suspicious of their speed. If I find a good implementation, I have no problem adding it to SDM.

    2) That is certainly possible (as an option). Don’t expect a 100% certainty, though – an extra thread could be opened quite a lot later than the other threads.

  38. pepak pepak napsal:

    Version 0.12 adds geolocation of users, ability to not monitor downloads by certain users (e.g. administrator) and ability to ignore multiple downloads of the same file performed by one user in short succession (such as when a download accelerator is used).

  39. samontab samontab napsal:

    Excellent!, thank you very much for adding those features.

    Although I have a problem. In my website the country flags are not being displayed. Everything seems to work fine except the display of the country flags (there is just a blank space).

    I updated the plugin via the wordpress admin page. What can be wrong?

  40. samontab samontab napsal:

    OK I managed to solve the flags problem.

    In the readme file you say that this plugin uses another plugin from you, IP-to-Country. This is available from http://www.pepak.net/wordpress/ip-to-country-plugin/
    But after I installed it, I could not update the IP sources because there was an undefined function:

    Fatal error: Call to undefined function zip_open()

    For solving that, I just unzipped the file locally and then manually uploaded the csv file.

    Now it is working, although I think many users will have the same issues when installing the plugin directly from wordpress.

    Anyway, thanks again this is a great plugin and now it has all the features that I need.

  41. pepak pepak napsal:

    That’s why I wrote „If you want it to work with ZIP files (e.g. for updating IP-country info from the default location), your PHP must have extension php_zip enabled“ in the plugin’s description.

  42. khong khong napsal:

    Hello,
    Thanks again for this awesome plugin. Nevertheless, when i update a exsiting file, by replacing it and checking „Remove old file?“. I got a error at the top of the page:

    Warning: strstr() [function.strstr]: Empty delimiter in /…/…/…/wp-content/plugins/download-monitor/admin/admin.php on line 418

    But the updates are done.

    Is it terrible Doctor?
    ^o^

  43. pepak pepak napsal:

    Are you sure you are asking at the right place? The error message seems to come from a „download-monitor“ plugin, not from my Simple Download Monitor. Aside of the unusual directory name (which is possible with SDMon), there’s the fact that there is no admin.php file in my plugin, not to mention that I am not aware of any „update existing file“ functionality of SDMon.

  44. Mark Z. Mark Z. napsal:

    Hello pepak,
    Thanks for the plugin. I have a dumb question to ask: How do I access the logs, specifically the detailed log?

  45. pepak pepak napsal:

    When you log in to your WordPress with sufficient rights (admin for full access, moderator [I think] for read-only access), you will see the „Simple Download Monitor“ menu in „Tools“ section. That’s what you are looking for.

  46. luka luka napsal:

    hi pepak i don’t know how to install that download monitor :( i dont know where its .htaccess file? can you help me please… by

  47. pepak pepak napsal:

    .htaccess file should be located in the root of your WordPress installation. You may not be seeing it, though – FTP servers tend to hide files starting with a dot from casual viewing. You may need to set up your FTP client, whichever you use, to use a custom LIST command LIST -la.

  48. luka luka napsal:

    can you give me your msn skype? i am not pro for that programing…

  49. pepak pepak napsal:

    In that case I would recommend to contact your webhoster. It is quite possible you will need their support anyway, since many hosters don’t provide .htaccess and/or mod_rewrite at all (in which case you can’t use Simple Download Monitor, because it relies on mod_rewrite), and others only allow them on a „ask us and we will update them for you“ basis.

    I am sorry, but I don’t use instant messaging clients, including those you suggested.

  50. rosa rosa napsal:

    How can I display the number of downloads of a particular file within the post? Is this possible?

  51. pepak pepak napsal:

    It is possible in theory (I think), but it’s not implemented in the current version.

  52. Dave Dave napsal:

    Hi Pepak, thanks for taking the time to make this plugin. I also like your site and appreciate all the help you’ve given in the posts. I hope you can help me. I installed the program with no apparent problems and used the default files/ target for all my files.

    When trying to edit the .htaccess file, I have nothing in mine. It is blank. My site works fine, but the plugin doesn’t seem to be calculating downloads. Should I still add the „RewriteRule ^(files/.*) /index.php?sdmon=$1 [L]“ line to my blank .htaccess file?

    I confess that I’m a bit of a novice at WordPress but I’m savvy and have downloaded and installed a number of plugins without trouble. I primarily want to be able to track PDF file downloads from my site (and I added |pdf| to the settings), but I must be doing something wrong still. Any help is greatly appreciated. Thank you! :)

  53. pepak pepak napsal:

    First we need to find out why is your .htaccess file empty. It can mean one of three things:

    1) You made an error while downloading the file. This is not as unlikely as it sounds, since many (most?) webservers are configured to hide files starting with a dot. So it is quite conceivable that you do have a .htaccess file, but your FTP client didn’t show it to you. Please make sure this is not the case and you really don’t have a .htaccess file – most FTP clients should have a setting to „show hidden files“, or alternatively, „use a custom list command“ (you would use LIST -al in the latter case). Also, make sure you are looking in the right place – the .htaccess should be in the root of your WordPress installation (where files such as wp-config.php or wp-app.php are located).

    2) It may be that your WordPress installation doesn’t use mod_rewrite for nice URLs. What do the addresses of your blog articles look like? If it is something like http://www.myblog.com/?p=123 (as opposed to, say, addresses, used on my blog, such as http://www.pepak.net/wordpress/simple-download-monitor-plugin/), then it is quite conceivable that you don’t have any predefined .htaccess. Otherwise it is almost certain you do have a .htaccess located somewhere – I would recommend asking your webhoster then.

    3) If you really don’t have a .htaccess file, you may use the default one provided with WordPress, where you add the extra RewriteRule line. You could also write a .htaccess file from scratch, but unless you are experienced with it, chances are that you won’t be able to write a correct one (I know I fail most of the time…).

    *) Actually, I have just downloaded a new WordPress installation to make sure a .htaccess file is there, and it isn’t. It seems WordPress will generate this file „on the fly“ when you select a relevant Permalink setting. Try that. If that fails, you can try this content:
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /

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

    #WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    4) When you have your .htaccess file, Simple Download Monitor should start working – if your webhoster supports mod_rewrite, that it. The easiest way to verify it would be switching to „cool URIs“ and checking if your website still works. The problem is, different webhosters have a radically different approach to mod_rewrite – you may be able to write your own .htaccess, but you may also need to send your proposed modifications to your webhoster so that they change the setup „by hand“ – and yet other webhosters won’t let you use the feature at all.

  54. Dave Dave napsal:

    Pepak, YOU ROCK!!! Thank you so much! The problem was that I did have a .htaccess file but it was empty (perhaps because I am not using any permalinks). I edited the file and added your recommended text, saved it, uploaded it via http://FTP... and now everything works AWESOME!!! Downloads are calculating perfectly! Thank you so much!!! I really appreciate the help!!!

  55. Dave Dave napsal:

    Hi again Pepak, Thanks again for the help, along with the code to setup my .htaccess file. It worked perfectly, however, I noticed the other day that my downloads stopped calculating. Out of curiosity I checked the contents of the .htaccess file and it was empty! Is this something I should contact my hosting company about? What would make the .htaccess file clear out like that? Any clues? Thanks again! :)

  56. pepak pepak napsal:

    I suspect your WordPress might be doing that. Now I am not 100% certain that it works this way, but I wouldn’t be surprised if WordPress refreshed the .htaccess file when you change some of its options (probably those in the „permalink“ cathegory). Why don’t you fill your .htaccess to the contents that used to work for you and then start trying to enter and save each settings submenu, always checking the .htaccess file before moving to the next submenu. Eventually you should find which one is causing you problems.

    Another suspect might be some plugin you use, although I find this hard to believe.

    A thought: Maybe try to remove the # BEGIN WordPress/# END WordPress, or move it around a bit:
    RewriteEngine On
    RewriteBase /

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

    # BEGIN WordPress
    #WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

  57. Daniel Daniel napsal:

    Hi ;)

    Very nice plugin. Thank you so much for it! But I found an error at the date format (in the monitor for the admin to view the statistic). At your sourcecode there are two lines with „h:i:s“, but for a correct date output it must be „H:i:s“. Please correct it, thx.

    Daniel :-)

  58. pepak pepak napsal:

    I will. Thank you for the report.

  59. pepak pepak napsal:

    Version 0.13: Mostly cosmetic fixes, such as Daniel’s time fix, better paginator display, official support for WordPress 3.0 etc.

  60. Wallace Wallace napsal:

    Hi,
    the plugin is really simple and useful,
    but why i cannot see any flag inside the stat page?
    pls email me back, thanks your help!

  61. pepak pepak napsal:

    Because you didn’t read the right part of the documentation – you need to check the changelog for version 0.12. (I’ll add it to the Installation instructions in the next version.)

  62. Daniel Daniel napsal:

    Hi ;)

    yeah thanks for the update! But I’ve a question refer to the download process. You use the byteserve method I see in your sourcecode. I noticed that some poeple downloaded files more than one times. The file is a zip archive and is round about 500mb. Can it be that the byteserve method has a problem with such a big file? If I downloaded the big archiv, all was fine. But I think users with a small bandwith or an bad broadband connection can get a problem. Is it possible that you enter a choice in the admin panel where you can choose between the normal download method and the byteserve? Only an idea. Or I will pass on such big archives (or separate the archives in some smaller ones).

    Daniel :-)

  63. pepak pepak napsal:

    1) Could „byteserve“ method cause problems for some people? It is possible. I don’t think it likely, but it may happen. But I think the „multiple downloads“ you see are really just one download, but running in several independent threads (some download managers do that to speed up the downloading).

    2) Could „byteserve“ be replaced by a „normal“ download? Yes, it could. In fact, SDMon versions prior to 0.09 supported it. But the drawback of moving away from „byteserve“ is that it wouldn’t be possible to resume downloads anymore.

    3) Would it be possible to combine the best of both worlds? Yes, but it would be difficult. You would need to play with .htaccess (or, more specifically, with mod_rewrite) to NOT redirect a download to Simple Download Monitor when some condition is met. You would need to change the current download sequence:
    (i) user requests a file /files/xyz.zip
    (ii) mod_rewrite rewrites this request to /index.php?sdmon=/files/xyz.zip
    (iii) SDMon logs the requests and sends the requested file to the user
    To something like this:
    (i) user requests a file /files/xyz.zip
    (ii) mod_rewrite rewrites this request to /index.php?sdmon=/files/xyz.zip
    (iii) SDMon logs the requests and redirects to e.g. /files/xyz.zip/real-download
    (iv) user requests a file /files/xyz.zip/real-download
    (v) mod_rewrite rewrites the request to /files/xyz.zip and stops processing
    (vi) Apache sends the file to the user
    But even then, it would be problematic to support resumable downloads, because you would need to distinguish between the first request for /files/xyz.zip (=log and download) and the second, third etc. request (=just continue with the download).

  64. Richie Richie napsal:

    Was having problems with this plug not working. I took my uploads folder and put it in the files folder, configured the options but still didn’t get any results.

    After playing with the .htaccess file, I still couldn’t get anything. Then I remember that I had permalinks set to /%postname so mod_rewrite was already doing funny stuff. After messing around this is what worked for me. For those who are using search engine friendly permlinks, try this in your .htaccess file.

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^(files/.*) index\.php?sdmon=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Those developing on localhost will have a different rewritebase like

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /yoursitename/
    RewriteRule ^(files/.*) index\.php?sdmon=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /yoursitename/index.php [L]

    # END WordPress

  65. Richie Richie napsal:

    Is there shortcode to display the downloads count in the front end posts for individual links?

  66. pepak pepak napsal:

    No. I may add some in the future.

  67. Richie Richie napsal:

    While your at add an ignore function too cause files like jpgs that are in the files folder produce a 404 if not added to the explicit list. When you do add them, you’ll get a 200, but then it will record the image as a download.

  68. pepak pepak napsal:

    That is better handled through .htaccess, IMO.

  69. Richie Richie napsal:

    Yes I agree pepak. After some more googling, this is what I ended up with. A much more elegant solution. Since I added sdmon after my uploads folder was already full of jpgs, pngs, and mp3′s, I needed a way just to reuse the uploads folder in its entirety. I just renamed it to ‘files’ and moved it out of the wp-content folder into the root.

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /

    # Just make sure this rewrite condition comes before the rewrite rule for sdmon
    # This rewrite condition will bypass sdmon’s processing and resolve 400 errors
    RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|swf|flv|wav|jpeg|mpeg|mov)$

    # This rewrite rule is slightly altered from sdmon’s native rule. This allows search engine friendly
    # links based on the permalink setting of /%postname%
    RewriteRule ^(files/.*) index\.php?sdmon=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Thanks for everything Pepak. I’ve also managed to build a download counter for post loops using the get_children wordpress function, php’s substr, and querying wp_sdmons_downloads database.

Leave a Reply

Themocracy iconWordPress Themes