img Hey! I'm a French WordPress developer! Welcome on my site!
  • Follow me:
Easy Download Media Counter Free Plugin
29th May

2012

Easy Download Media Counter Free Plugin

Today i was thinking about a nice little plugin that be could very useful: a download counter for WordPress media. I took a look on the internet and didn’t find what i was looking for, so i decided to do it myself. What i was thinking about was pretty simple: count downloads for media that are listed in the wordpress library and provide two shortcodes: the first one to display the download link, and the second one to display the number of times a media was downloaded.

So basically, the plugin offers these two shortcodes, and to make it a bit more useful i added a field in the edit media page, where you can manually modify the downloads value.

Here are the shortcodes to use:

  • (edmc id=”xx”)Download the file(/edmc) - Link to download the file
  • (edmc_show id=”xx” - Returns the sentence “Downloads: xx”
Please note that you must replace ( ) by [ ], and xx by the media ID. You also provide a download link without using shortcode, just add ?edmc=xx to any url and tada !! The magic appears ! 5don’t forget to replace xx by the media unique ID). And a last thing, one line 112 you can define the download file name.

Gallery

Code

Revision

A little bug has been fixed thanks to Cosmin Popovici

Changelog

June 10 2012: Version 1.1
- Added downloads column in media library

Share This :

Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!

Comments

Kasper

2012-06-06 13:47:35 Reply

Dear Remi,

Thanks a lot for offering this plugin for free.
However I do wonder if it’s possible to let it count a link that doesn’t refer to a downloadable item. I’ve tried it by adding the ?edmc=xx to a page link, but upon clicking it will give a message to download a 0 byte file.

What I would like is to just have visitors click a link on my site, go to the direction that link is pointing. But being able to post a counter as to how many people have clicked that link before them.

Looking forward to hear from you,

Regards,
Kasper

Dave Reed

2012-06-13 03:37:59 Reply

Hi, Remi:

I first must admit being rather new to WP so please bear with me on this. I wanted to try this but I’m missing something about how to write it in. You say to use the unique media ID, but I have no idea what that is. I’ve looked everywhere and find no Media ID field, so I’m not getting something here….

    Rémi

    2012-06-13 08:28:29 Reply

    Hi Dave ! No worry! Ok, first of all you have to understand that every media in WordPress as a unique identifier in the database. It’s a number that is auto incremented each time a new media is added. It’s the same for post, page etc… You find this unique ID there are several methods, but the easiest is to go on the media page in the administration, and edit the media you want to find the ID.

    When you are on the edit page, just have a look on the URL. It should be something like that:

    http://yoursite.com/wp-admin/media.php?attachment_id=532&action=edit

    There are two parameters, and the one we need is: attachment_id. Here its value is 532. This is the value you have to use in your shortcode!

    Let me know if you manage to do it!

      Dave Reed

      2012-06-13 21:15:24 Reply

      Coolio! It’s gonna be a few days but that is what I think I need to know. I’ll get back in a few.

      Thanks.

Mo

2012-06-27 09:34:29 Reply

Thanks a lot,
it works simple. http://www.mo-ment.de/typomas-zum-download/

In the wordpress-plugin-site I missed the end tag for the url shortcode, I found it here.

thx

mo

    Rémi

    2012-06-28 08:30:52 Reply

    Thanks Mo to share a plugin live preview !

      Mo

      2012-07-06 07:09:27 Reply

      Crazy. Download does not work yet. Every file, I downloaded with your plugin, is broken with 1,5 KB only. Whats to to?

        Rémi

        2012-07-06 08:09:32 Reply

        that’s weird. Can you please try deactivate all plugins except this one and see if it’s working? i don’t have this issue.

Mo

2012-07-10 10:30:40 Reply

No, this try failed. No Change. I need a different link structure.
this Link does not work: http://www.mo-ment.de/?edmc=1484
also not http://www.mo-ment.de/wordpress/?edmc=1484
every time only download of the name (? 1,5KB), not the file.
only http://www.mo-ment.de/wordpress/wp-content/uploads/2012/06/typomass_mo-ment1.pdf works.

I have to deactivate your plugin, sorry, no counter yet.

    Rémi

    2012-07-10 10:34:11 Reply

    Did you check your server CHMOD? It seems that the content of your file can’t be inserted in the file to download. Can you confirm that the repo is writable?

    Rémi

    2012-07-10 10:36:22 Reply

    I am using the plugin with wordpress 3.4.1 and it’s working: http://remicorson.com/?edmc=834

mo

2012-07-10 11:28:57 Reply

OK, it crashed since I have 3.4.
I try to update, asap.

mo

    Rémi

    2012-07-10 11:58:56 Reply

    ok, let me know!

mo

2012-07-10 12:12:35 Reply

3.4.1. no change

Can you confirm that the repo is writable?
What do you mean “repo” ? :-/

    Rémi

    2012-07-10 12:39:44 Reply

    the directory, the folder; sorry mate! :)

mo

2012-07-10 13:54:02 Reply

Sorry, which one folder I mean?

    Rémi

    2012-07-10 13:56:36 Reply

    The folder that contains the plugin, and if needed the folders above.

Mo

2012-07-10 14:01:50 Reply

I give up.

content / plugins / your Plugin / and all files are writable … nothing .

    Rémi

    2012-07-10 14:04:11 Reply

    that’s weird, it’s working on many other websites…

Mo

2012-07-10 14:16:13 Reply

I bet, it works when I installed this first time. I dont know, where the probleme is come from, because I changed nothing. (I installed under WP 3.4)

grrrmpff

mo

2012-07-10 17:18:15 Reply

Ahhh. It works with images (JPEG) but no PDF-file.

Idea?

    Rémi

    2012-07-10 17:26:09 Reply

    not yet, but i’m going to investigate !

Jan Kasal

2012-09-21 11:34:57 Reply

Hi Rémi, I am having the same problems as mo has. The counter worked when I established the link. Then, one day, I got alerted that the file was corrupt. I checked and the download dialog box displayed that the file to download was 0 kb in size.

    Rémi

    2012-09-21 11:48:45 Reply

    Hi, what kind of files ? It seems that its working well with JPEG and GIF but not with PDF, do you confirm ?

      Jan Kasal

      2012-10-05 14:54:16 Reply

      I tried to monitor downloads of pdf files only, so I can confirm the malfunction of those only.

        Rémi

        2012-10-05 15:54:39 Reply

        Thanks Jan for the heads up !

Tiago Pascoal

2012-10-02 23:37:32 Reply

I believe i’ve found the code of the corrupted file some people are reporting.

It is happening because you are getting the file path (physical) using wp_upload_dir()( http://codex.wordpress.org/Function_Reference/wp_upload_dir) and this returns the path including the current month (when this option is configured on the backoffice).

So if you uploaded the file last month (09) the download will work until the month rolls over.

When you upload the file, it would be stored on …/wp-content/uploads/2012/09

In october it will stop working since the download folder will become …/wp-content/uploads/2012/10

If you look at the content of the corrupt file you will see something like

Some real path ommited

Warning: filesize() [function.filesize]: stat failed for [WP ROOT FOLDER]wwwroot/wp-content/uploads/2012/10/MYFILE.ZIP in [WP ROOT FOLDER]wwwroot\wp-content\plugins\easy-download-media-counter\easy-download-media-counter.php on line 137

Warning: readfile([WP ROOT FOLDER]wwwroot/wp-content/uploads/2012/10/MYFILE.ZIP) [function.readfile]: failed to open stream: No such file or directory in [WP ROOT FOLDER]wwwroot\wp-content\plugins\easy-download-media-counter\easy-download-media-counter.php on line 139

So this is the cause, the fix i’m not sure if it’s that simple :-)

I’m not versed on wordpres, but the file path seems to be available as part of the media, so perhaps a redirect could be used to the “real” path or check if this option is enabled and deduce from the “real path” the month

    Rémi

    2012-10-03 08:59:28 Reply

    Thanks for the heads up, i’ll send a new version with a patch asap. Maybe next week.

Leon

2012-10-03 03:52:28 Reply

Hey Rémi,

I’m having the same issue too.

At first it worked great, but then I replaced the file with a FTP with a new version and I started having the same issue as Jan and mo.

The file is a zip. The only change was replacing the file. Direct download (trough …wp-content/uploads/… URL) works fine.

I initially uploaded the file with WP, then replaced it via FTP (because it’s a fairly large file) – it worked fine, but stopped working when I replaced it again recently. Nothing else was changed (on WP or the server; the filename is the same), just the file contents.

    Rémi

    2012-10-03 08:58:45 Reply

    Ok, i’m going to see what’s going on release an update. Thanks for the heads up!

rafael rumbos

2012-11-05 00:06:15 Reply

The plugin is not working maybe i am doing something wrong here

[edmc id='1']The Debian Chip Descargar[/edmc] [edmc_show id='1']

the counter works but shows a “() ” at the end but the file linked to the text dont download properly (boken download) please a fix!!!

    Rémi

    2012-11-05 10:35:04 Reply

    Hi, it’s because you are not using the plugin as you should. The way you insert the shortcode isn’t good. Simply use the shortcode without any “a” tag, it’s automatically inserted. Please read the documentation.

Eduardo

2012-11-10 13:56:41 Reply

Hi Rémy,
In my website I manage mp3 files that can’t be uploaded by the WordPress system because are too large (25 Mb or more). So, they have not id number. Could be another way to use your plugin?

Thanks,

Eduardo

    Rémi

    2012-11-10 14:45:22 Reply

    I am afraid that without ID, you wont be able to use the plugin.

      Eduardo

      2012-11-10 14:51:14 Reply

      Well, thanks anyway.

WallpaperEVO

2013-02-03 20:05:16 Reply

I have the same problem with downloads it give me 0kb file.
When you will release the update?

Here is a live preview of the problem:
http://wallpaperevo.com/2013/01/2014-chevrolet-corvette-wallpaper/
click on “Download Wallpaper” and you will get only 0kb JPG.

Regards.

Rémi

2013-02-05 10:51:29 Reply

I just fixed it in version 1.2

    Cosmin

    2013-04-02 12:44:40 Reply

    It’s not fixed, it still fails with 0-byte files.

    WordPress folders chmod: 755
    Files chmod: 644
    Owner : www-data

    Trying to get a file with spaces in the name fails with 0-bytes (empty file), i.e. “My Awesome File.jpg”. If checking with file_exists(), you can see it will return FALSE.

Paul

2013-05-10 12:46:56 Reply

Hey Rémy, tank you for this plugin! Can you tell me one thing? The shortcode ID . ‘”]’ ) ?> shows me the numbers of downloads, right? But it also shows me the type of media – and i don’t want that. Wher to modify your plugin, to hide this information? I show the mediatype on an other place…

Can you please tell me? Thanks a lot for your plugin and the answer!

Best reguards!

    Remi

    2013-05-10 12:55:03 Reply

    hi, it’s on line 90 in easy-download-media-counter.php

Leave a Comment

Your email address will not be published.