Installing a download counter - review of plugins for WordPress. Creating a file download counter using PHP and MySQL Saving text and graphic files

On many sites you can see links to download files. For example, manufacturing companies post instructions for a particular product on their official pages. In addition, the developers software They also offer to download their program for free, thus allowing the user to become familiar with its functions and operation.

When making a file available for free download, it is important to know how many times it has been downloaded. This is necessary, first of all, for statistics, the analysis of which will help determine the usefulness of the information for the end user.

How to set a download counter on a WordPress site?

There is no way to see these statistics among the WordPress tools. Therefore, we will use a third-party solution - the Kama Click Counter plugin.

Kama Click Counter plugin

The free Kama Click Counter plugin provides all the necessary tools to accurately count the number of downloads of a particular file. So, firstly, it needs to be installed and activated. For example, we will display on the post page a link to a pdf file, for which we will count the number of downloads. It should be noted that files are uploaded to the site using standard methods WordPress Media Libraries (Media -> Add New). Next, you need to open the post or page for editing. In the content part, you need to place the cursor in the place where the link to the file will be placed, and click the button that appears in the visual editor toolbar.

In a pop-up window, the plugin will ask you to select the previously downloaded file. To do this, press the button with the magnifying glass icon.

In the media library you should select required file and click the Select file button.

As a result, a special shortcode will be inserted into the content part of the post or page, which serves to display a link to download the file.

After updating the material (Update button), you can go to the site to view it.

The plugin is also able to show download statistics in the user part of the site – in a widget. Note that by default the plugin does not show specific numbers in the widget about what was downloaded and how many times. Only a list of the most frequently downloaded files is displayed. To do this, go to the admin section Appearance -> Widgets and drag the KSS:Top Downloads widget to the desired location in the sidebar.

You can see that the widget has several options available that allow you to modify the list.

Here you can set the following basic parameters:

  • widget title (Title field);
  • number of output files in the list (how many links to show?);
  • sorting the results (how to sort the result?);
  • setting appearance template (Template and CSS template blocks).

A special feature of the plugin is its flexible template customization. Here you can use so-called tags, in place of which this or that information will be displayed.

After all the widget settings have been completed and saved (Save button), you can view the result on the website.

There have been no lessons about PHP and MySQL for a long time. Today we will create a simple but effective download counter.

Each file will have an entry in a database table row. The number of file downloads will be stored in the same table. PHP will update the MySQL database and redirect the user to required file.

To track the number of downloads of any file, you need to put it in the files folder and use a special URL to access it.

Step 1 - XHTML

The first step is to create the markup for our script. It's very simple - we have a div file-manager that contains an unordered list, in which each element of the list is responsible for a file.

The files whose downloads need to be tracked are placed in the files folder in the root folder of the script. PHP then goes through all the files and adds each one as a list element (li) to the unordered list.

demo.php


  • photoShoot-1.0.zip 0 download

Note that the href attribute of the links passes the file name as a parameter to download.php. This is where the tracking of the number of downloads takes place.

You don't have to display everything the same way - you can simply link to download.php on your pages and all downloads will not go through.

Step 2 - CSS

After marking, let's start with the design. The CSS rules below refer to the file-manager div using id (# symbol), since it appears only 1 time on the page, and to other elements by class names.

styles.css

#file-manager( background-color:#EEE; border:1px solid #DDD; margin:50px auto; padding:10px; width:400px; )
ul.manager li( background:url("img/bg_gradient.gif") repeat-x center bottom #F5F5F5; border:1px solid #DDD; border-top-color:#FFF; list-style:none; position:relative ; ) ul.manager li a( display:block; padding:8px; ) ul.manager li a:hover .download-label( /* When hovering over the icon, show green download text: */ display:block; ) span. download-label( background-color:#64B126; border:1px solid #4E9416; color:white; display:none; font-size:10px; padding:2px 4px; position:absolute; right:8px; text-decoration:none ; text-shadow:0 0 1px #315D0D; top:6px; /* CSS3 Rounded Corners */
-moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; ) span.download-count( color:#999; font-size:10px; padding:3px 5px; position:absolute; text-decoration:none; )

Step 3 - PHP

As I said before, PHP looks for files in the files folder and outputs each file as a list item in an unordered list. Let's take a look at how this happens

demo.php - top part

// Error reporting: error_reporting(E_ALL^E_NOTICE); // : require "connect.php"; $extension=""; $files_array = array(); /* Open the folder and go through all the files: */ $dir_handle = @opendir($directory) or die("There is an error with your file directory!"); while ($file = readdir($dir_handle)) ( /* Skip system files: */ if($file(0)==".") continue; /* end() displays the last element of the array generated by the explode() function: */ $extension = strtolower(end(explode(".",$file))); /* Skip php files: */ if($extension == "php") continue; $files_array=$file; ) /* Sort the files in alphabetical order */ sort($files_array,SORT_STRING); $file_downloads=array(); $result = mysql_query("SELECT * FROM download_manager"); if(mysql_num_rows($result)) while($row=mysql_fetch_assoc($result)) ( /* The $file_downloads array key will be the name of the file, and will contain the number of downloads: */ $file_downloads[$row["filename"] ]=$row["downloads"]; )

Notice how we select all rows from the download_manager table using mysql_query(), and later add them to the $file_downloads array with the file name as a key to the number of downloads. Thus, further in the code, we can write $file_downloads["archive.zip"] and display the number of downloads.

Below you can see the code that generates the list items:

demo.php - middle part

Foreach($files_array as $key=>$val) ( echo "

  • ".$val." ".(int)$file_downloads[$val]." download
  • "; }

    Everything is done simply using a foreach loop on the $files_array array. After this everything is output using echo.

    Now let's take a closer look at how file tracking works.

    download.php

    // Error checking : error_reporting(E_ALL^E_NOTICE); // Include the connection file to the DB: require("connect.php"); if(!$_GET["file"]) error("Missing parameter!"); if($_GET["file"](0)==".") error("Wrong file!"); if(file_exists($directory."/".$_GET["file"])) ( /* If the visitor is not a search bot, we count the download: */ if(!is_bot()) mysql_query(" INSERT INTO download_manager SET filename ="".mysql_real_escape_string($_GET["file"])."" ON DUPLICATE KEY UPDATE downloads=downloads+1"); header("Location: ".$directory."/".$_GET["file"] ); exit; ) else error("This file does not exist!"); /* helper functions: */ function error($str) ( die($str); ) function is_bot() ( /* This function checks for a robot */ $botlist = array("Teoma", " alexa", "froogle", "Gigabot", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot ", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz", "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot", "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler", "TweetmemeBot", "Butterfly", "Twitturls" ,"Me.dium","Twiceler"); foreach($botlist as $bot) ( if(strpos($_SERVER["HTTP_USER_AGENT"],$bot)!==false) return true; // Is a bot ) return false; // Not a bot )

    It is important to check whether your visitor is a human or a search engine robot. Robots are certainly good, but let’s not let them distort our statistics. This is why the row in the database is updated only after the is_bot() check.

    Step 4 - MySQL

    As we noticed in the previous step, the number of downloads is stored as a row in the download_manager table. First, let's explain how this request works:

    download.php

    INSERT INTO download_manager SET filename="filename.doc" ON DUPLICATE KEY UPDATE downloads=downloads+1

    It tells MySQL to insert a new row into the download_manager table, and set the row's filename field to the value of the file called for download. However, the filename field is designated as a unique index in the table. This means that each row can only be inserted once, otherwise a duplicate key error will occur.

    This is where the second part of the query will work - ON DUPLICATE KEY UPDATE will tell MySQL to add one to the downloads column if the file already exists in the database.

    This way, new files will be automatically added to the database the first time they are downloaded.

    Step 5 - jQuery

    In order to do real-time tracking, it would be good to update the counter next to the file name after each download.

    We'll do this using jQuery:

    script.js

    $(document).ready(function())( /* The code is executed after the page is loaded */ $("ul.manager a").click(function())( var countSpan = $(".download-count",this) ; countSpan.text(parseInt(countSpan.text())+1); )); ));

    We simply assign a click handler to the links that lead to the files, and on each click we add a value.

    Step 6 - htaccess

    There is one more thing that needs to be done. Download.php redirects the user to the requested file that was passed as a parameter. However, you may have noticed that browsers try to open some types of files directly. We need to initiate their loading. This can be done with a few lines inside the .htacess file, which is located in the files folder.

    ForceType application/octet-stream

    Now our counter is completely ready!

    Conclusion

    In order for the demo to work, you need to recreate the download_manager table in the MySQL database. You can find the required SQL code in the sources.

    After this, add your data for connecting to the database in the configuration.php file.

    // Remove magic quotes mode conversion $_POST["content"] = addslashes($_POST["content"]);

    // Rewrite the contents of the file file_put_contents($_POST["filename"], "$_POST");

    4.9. File download counter

    The operation of all file download counters is based on the fact that the visitor is not given the file itself as a download link, but a link to a script that takes into account the download and sends the file to the user’s browser.

    We will build our counter in such a way that links to download a file are links to the current page, passing the file name as a parameter, for example, index.php?down=archive.zip . The script will check to see if the down parameter is passed, and if so, it will log the archive download in filecount.txt. When the page is reloaded, the counter values ​​for each archive will be extracted from the file for output to the browser window. The file will be transferred for download by sending the HTTP Location header to the visitor indicating the path to the downloaded archive. The file download counter script might look like the one shown in Listing 4.31.

    Listing 4.31. File download counter

    // Set the error handling level error_reporting(E_ALL & ~E_NOTICE);

    // Register file names in an array

    $file_name = array("archive1.zip","archive2.zip","archive3.zip");

    // Name of the file where statistics are stored $countname = "filecount.txt";

    // If the file exists,

    // read current statistics into an array if(file_exists($countname))

    // Get the contents of the counter

    $content = file_get_contents($countname);

    // Unpack the array

    $count = unserialize($content);

    // If there is no such file, create it,

    // and reset the statistics

    // Fill the $count array with zero values ​​foreach($file_name as $file)

    $count[$file] = 0;

    // Pack the array and place it in the counter file_put_contents($countname, serialize($count));

    // Check if the value of the down parameter is passed

    // via the GET method

    if(isset($_GET["down"]))

    // Check if the value of the $_GET["down"] parameter is included

    // into the $file_name array

    if(in_array($_GET["down"],$file_name))

    // Register the fact that this file has been downloaded

    //Increase the value of the counter with the key

    // $_GET["down"] by one

    $count[$_GET["down"]]++;

    // Overwrite the counter file file_put_contents($countname, serialize($count));

    echo "The file $file was loaded ".intval($count[$file])." times
    ";

    The names of downloaded files are stored in the $file_name array; adding a new archive results in its automatic registration in the system. Pre-registration in the array is necessary for several reasons. First, when accepting an array name via the down parameter, you need to check whether it is among the files allowed to be loaded. Secondly, it is much more convenient to process file names in an array. Thus, the $count array, which stores the number of file downloads, is automatically built based on the array of files registered in the system,

    It is convenient to pack an array into a string using the serialize() function, and then unpack it back into an array using the unserialize() function.

    NOTE

    It is important to remember that all HTTP headers must be sent before the main content is sent, otherwise they will not be sent and the PHP interpreter will issue a warning "Warning: Cannot modify header information - headers already sent by"

    (Warning: It is not possible to modify the header information - the headers have already been sent). This is dictated by the HTTP protocol: the headers are sent first, then the contents of the document, so any output to the browser window is perceived as the end of sending the headers and the beginning of sending the body of the document. If output to the browser window is unavoidable before the headers are sent, you must resort to output control functions, placing all output in a buffer and sending it at the end of the script.

    As you can see in Listing 4.31, the script handles the first-run situation where the filecount.txt file is missing - it is automatically created on the first page load, triggered by zero values ​​for each file in the $file_name array. The result of the script from Listing 4.31 can be seen in Fig. 4.4.

    Rice. 4.4. The result of the file counter

    4.10. Saving text and graphic files

    Following a link to text or HTML files results in them being displayed in the browser window, which is not always convenient, especially if the file is intended to be downloaded. The same fate awaits graphic files and, in general, any files that the browser can display. The visitor's browser "learns" about the contents of the file from the server, since each file is accompanied by HTTP headers that inform the client about the content, the size of the downloaded file, the need to set a cookie, etc. If the file type could not be determined, it is sent simply as binary stream.

    You can suppress this behavior by sending the HTTP headers shown in Listing 4.32.

    Listing 4.32. A script that allows you to save text and graphic files

    $filename = basename($_GET["down"]); header("Content-Disposition: attachment; filename=$filename"); header("Content-type: application/octet-stream"); header("Content-length: ".filesize($_GET["down"]));

    echo file_get_contents($_GET["down"]); ?>

    The script in Listing 4.32 takes a filename as a GET parameter, for example,

    index.php?down=filetext.txt. The basename() function retrieves the name

    file (in case the GET parameter down contains the path to the file). The Content-Disposition HTTP header specifies the name of the file to be saved, which is determined by the filename attribute. In the above script, the filename parameter is the same as the name of the file being sent, however, an arbitrary name can be passed as the filename parameter. The Content-type HTTP header indicates that the data being transferred is binary and should not be interpreted by the browser. The Content-length HTTP header conveys the size of the file to the client. The last line displays the file contents passed through the $_GET["down"] parameter, which are retrieved using the file_get_contents() function. The result of the script from Listing 4.32 is shown in Fig. 4.5.

    NOTE

    It is important that after outputting the contents of the file, nothing else is output to the stream: neither by the echo construct nor by direct output - otherwise everything will be appended to the end of the file. This applies to both possible spaces and newlines after the ending ?> tag.

    Rice. 4.5. Dialog box for downloading a file

    The next question that I recently became interested in when setting up my simple author’s project was the question of how to count the number of downloads of a particular file posted here. It was most logical to assume that this requires another plugin, some kind of download manager, or what is simpler - download counter. Having scoured the Internet, it turned out that, as usual, there are a wagon and a small cart of these plugins. But again, there are no reviews of them. It’s absolutely not clear what to choose, and as usual, I had to test everything on myself. And based on the testing results, this reviewer was created. It took a long time to write, and the goal was not to thoroughly test all the plugins given with a full review of their settings, so you won’t find detailed screenshots of each, but there will be key settings. I didn’t want to talk about some of them at all - they were so stupid, but since I looked at them, it was a shame not to write anything at all.

    Introduction.

    So, the task was to count the number of downloads of a particular file by setting a download counter for WordPress. Upon closer examination, it fell into several subtasks, or rather, wishes for a plugin that would fulfill it. Here is a short list of them:

    • It is necessary that the number of downloads be displayed somewhere in the admin panel, with the ability to sort - how many were downloaded per day, per week, month, year, total
    • It would be desirable to be able to see graphs/diagrams of file downloads relative to each other
    • It would be desirable to be able to see graphs/diagrams of file downloads over time
    • It is advisable to keep statistics on when the file was last downloaded
    • The ability to display information next to the link about how many times the file was downloaded, as well as its size, and the date of download for the user who is just about to download it. Well, or not to withdraw - at the request of the admin
    • The ability to insert the code responsible for this using a separate button in the post writing panel TinyMCE editor(I don’t like using quicktags)
    • Ability to limit download speed (just in case)
    • Attaching an upload function to this plugin (uploading files to the server) - on the contrary, I didn’t give up. FTP works well for me too. But if it doesn’t interfere too much, then let it stay
    • It would be nice to be able to attach a nice button to the download link - although for me it’s enough to write class="button"

    ABAP

    Download file!

    • It would be good if he counted the number of downloads not only from his website, but simply from the link
    • Possibility to ban direct download file without showing where it is on the server.

    Here's a small list.

    Review

    After we have decided on the technical specifications, we will begin to consider what is directly offered to us.

    1. Download Counter 1.2 plugin, downloaded here.

    Initially, the plugin page was located, but the author has not supported it for more than 4 years. We create another folder for it in the plugins directory for me - download-counter, and drop both files there. As a result - where would you think? — settings for it appear in the records. Very original, but ok.

    Let’s go inside and write the path to the download-manager.php file (I really don’t like throwing any nonsense right into the root). And let's see what we got. Upload the file, check whether it is downloaded in manual mode, if you enter a direct link in the browser, enter the path in the plugin to create a counter. In theory, an ID should be created, which will then need to be inserted everywhere. But nothing worked - it gives the error “Error - Unable to save the recording.” Well, ok, we persuaded, we transfer it to the root download-manager.php - again nothing, same error. Well, to hell with you, goldfish, it wasn’t enough for me to still understand the plugins that the author didn’t give up on. Moreover, functionality is practically zero.

    2. Download Counter Advanced 1.1 plugin, downloaded.

    I’ll say right away that it didn’t really work for me either, so you can read about its installation and configuration only out of academic interest. Essentially, this is the same plugin, only slightly modified. Thank God, although the instructions have not been translated, you can read them normally and not try to understand what the translator meant. By the way, in the admin panel it appears to be a completely different plugin, offering to update (yes, what the heck). Similar to the previous plugin, its page was located, and similarly the author has not supported it for more than 4 years. By analogy, we create another folder for it in the plugins directory, mine is download-counter, and we throw all the files there. The settings look, of course, richer, although the download speed is limited for all files at once, and is not set for each one. Where is the file download-manager..php (don’t forget the name of the file at the end, but I guessed right the first time where all the downloads are, which plunged me into terrible amazement. As it turned out later, I guessed the name of the directory in which upload downloads, here my logic worked 100% identically with the author of the plugin.

    We add the names of the folders that we have on the server in the downloads directory (in the “categories and directories” settings) to make it easier to choose the path to the files. If you don’t add them, you’ll have to download everything to the downloads root. Save, you can add downloads. This is roughly what we get.

    Now let's try to insert it into the post. We add a link, in it we change our link to the code, which is issued directly in the plugin settings. And then... Fuck you! HTTP Error 500 (Internal Server Error): An unexpected situation occurred while the server was attempting to complete the request. Well, I was just going to tell you how to add a counter directly to a post, what if to the link inside to make it work

    ABAP

    < ahref= "http://chewriter..jpg" />

    then you can display a download button - it’s crooked, really. So much for the plugin, wasted your time. He doesn’t really keep statistics, because we won’t figure out where the glitch is.

    This is exactly the plugin to which the above-mentioned Download Counter Advanced was proposed to be updated. Well, he suggests - and okay, let’s download it and see. The plugin also has not been updated for more than 3 years, and some users even made corrections to its code themselves. It is installed quite successfully, the asceticism of the settings does not inspire optimism. By the way, well done too, they guessed where to place the settings - no worse than in the previous case. We add counters on the settings page, everything seems to be displayed as it should.

    Let's see what we have added to the post. Yeah, there are no buttons. Oh, of course, I forgot right there that everything is intuitive. Let's look at the instructions. It is necessary to construct a complex structure consisting of shortcodes like , downloaded , and at the same time (probably due to the CNC) it doesn’t really count anything.

    Therefore, we will not consider it further, together with the accompanying plugin Download Counter Chart, which displays information in graphical form.

    It was written by our compatriot, but unfortunately all it can do is display the number of people who downloaded the file next to its name - there are no statistics or any other goodies provided. However, if you are a lover of minimalism, this is what you need. Just don’t forget, there are no buttons, a shortcode like


    DIY download counter for WordPress

    you will have to enter it manually. It’s very good that the author described everything in detail, so I didn’t have to test it on myself.

    Well, if we’re talking about plugins written by our people, then we can’t help but mention one more. Its huge advantage is that it allows you to count not only the number of file downloads, but also simply clicks on links - it doesn’t matter whether they lead to a file or just to another page. Or to a file on someone else’s page :) He will also count this, or rather, theoretically he should count it. With statistics, it’s not all that great either, there are no buttons on the editing panel, and there are no restrictions on downloads either. But it's still interesting to see. Therefore, we download and install. In principle, there is a fairly detailed description on the author’s website, so I won’t go into too much detail. You must always keep in mind that if you need to set a counter on a file or on a link, you should use either a type shortcode or insert the class class="count" into the link. This, of course, is annoying; with a button it would be much more convenient. But the most annoying thing is that after all the efforts I could not get it to work adequately - if a shortcode was used, the download link itself was not displayed, and if a class was used, statistics on the links did not appear in the admin panel. Screenshots can be viewed from the author - if you like the idea itself, try it, maybe you will succeed.

    Really very simple. No shortcodes, etc. required. However, this plugin provides statistics only for the author; for visitors, next to the link to the file, it is not displayed.

    However, it should be noted that detailed statistics are kept on who downloaded which file and when. However, it is not very convenient to use.

    The settings include the following:

    • You can specify the directory from which files can be downloaded
    • You can specify the types of files that are allowed to download
    • Prevent counting file downloads as the author
    • Set the interval in seconds during which repeated clicks on a link from the same IP will be counted only once
    • Limit the number of files that can be downloaded from one IP per day
    • Use some kind of intermediate page with information that the download will begin now

    However, all this only works if you either (how would I put it more simply...) have permission to edit the .htaccess file, or if you specify the link directly by inserting it into

    However, since it did not have the ability to display statistics for users, and I did not want to remember the type of link, I stopped considering it at this point, deciding to return only if the other plugins in the queue were unable to solve the task.

    In terms of displaying information, this plugin is very similar to the one discussed in the previous paragraph. It differs in that it allows you to view statistics separately weekly, monthly, for any period, and simply the top 10. In terms of its capabilities, it is much more wretched; there are no statistics on the last download or on a specific file, not to mention the ability to introduce restrictions on downloading files. There is no clear documentation at all. I got the impression that this was just some kind of misunderstanding and not a plugin. I don’t even want to give screenshots, but to be objective, I’ll still give them, the author’s ones.

    Well, here we are at something more or less worthy. Almost half a million downloads - that's saying something. The official page of the plugin is located. In order to insert a file into a post, you need to use the arrow above the visual editor (the icon itself does not appear in it)

    And in the window that appears, select the required file (this is an example if it has already been uploaded via FTP)

    Then, click on the “Save new download” button

    and, going to the next screen, select the download format, and click on Insert into post. It is possible that nothing will happen. The plugin is slightly glitchy with latest versions WordPress. Therefore, you need to additionally click on the View Downloads link

    And then, having first selected the download format, click on the Insert link opposite the exact file that needs to be inserted.

    After which the corresponding shortcode like

    ABAP

    [downloadid="7592" format="1"]

    The plugin requires fine manual configuration, but no WYSIWYG is provided. The good thing is that you only need to set it up once. Detailed documentation is available at the author.

    Here's an example setup:

    ABAP

    (title)

    < ahref= "(url)" title="Downloaded (hits,"ни разу","1 раз","% раза"}">{title}!}

    It should be noted that declinations are not supported, i.e. if the file has been downloaded 21 times, and you have “raza” in your template, then it will sound somewhat un-Russian.

    And here is the option with the button:

    ABAP

    - (description), (size), Uploaded (date,"Y-m-d"), Downloaded (hits) times

    < ahref= "(url)" title="Downloaded (hits,"ни разу","1 раз","% раза"}">!} - (description), (size), Uploaded (date,"Y-m-d"), Downloaded (hits) times

    Looks like that:

    Well, after some modification, mine began to look like this (without buttons yet):

    Line code:

    ABAP

    (filetype_icon) (title) (File size: (size), Uploaded: (date,"d.m.Y"), Downloaded (hits) times)
    (description)

    The list of possibilities is quite wide:

    • You can upload files either using it (by clicking on the arrow), or specify the location where they are located, if they were uploaded earlier via FTP, you can simply specify the URL
    • Hides the true location of the file, you can substitute any necessary URL combination
    • You can use the download button, including your own
    • Downloads by the admin and all unnecessary IPs included in the counter exclusion list are not considered.
    • Should I count repeated downloads within a certain time from the same IP?
    • You can set several formats - with a picture, with a counter, without a counter, etc., and use each of them in the appropriate situation
    • There is an upload of the download log as a csv file

    If any mp3 or video file is being uploaded, you need to indicate for them whether it is force download or not. If force - then by clicking on it, it will be downloaded, if you do not check the box - play, then save - right-click. I would like to note that files uploaded with its help are not placed where your special directory for files was created, but in the wp-content/uploads/downloads/ created by it - you need to remember this, as well as the fact that when deleting them from statistics - files are also physically deleted from the server. With those that are uploaded via FTP, everything is OK. Plus, if you insert a link in different posts to the same file, then I didn’t understand whether it would summarize them. Unfortunately, it does not support any download restrictions, except that you can prohibit downloading to everyone except registered users. When you want to display the name of a file in the bottom line of the browser, or need to change it to its ID, you must remember to go to settings->permalinks and save the configuration there so that everything is written correctly in .htaccess - without this, the files will not be downloaded!

    Statistics are displayed in three places at once - in the console, in information about files, and in download logs. This creates certain inconveniences, for example, when you need to see when a file was last downloaded, but you can download statistics as a csv file and then sort it out in Excel. Considering that Excel has diabolical capabilities for constructing the necessary tables and charts, then maybe this is not bad. However, I think the screenshots will say more:

    Well, a screenshot of the log itself:

    At the same time, a huge plus is that a widget with statistics like this appears in the console:

    In general, we can say that after a little configuration, the plugin does its job just fine.

    This plugin was written by the same author as the WP-Polls plugin, which I, for example, use on this site. Although it enjoys, in comparison, an order of magnitude less popularity. But let's see if it's deserved. All documentation can be found on the author's website. At its core, the plugin is absolutely identical to the previous one - the template is written in exactly the same way, there are no restrictions on downloading, except for registered or unregistered users, and you also need to use a shortcode like

    ABAP

    [downloadid="7592"]

    Well, on the other points:

    • You can upload files using it (up to two MB, or whatever you have indicated in php.ini), and indicate the location where they are located, if they were uploaded earlier via FTP, you can simply specify the URL
    • Hides the true location of the file, but it is not possible to substitute any necessary URL combination, there are only a few fixed options, the main one of which did not work for me
    • Can be configured to display information to visitors about the size of the file, how many times it was downloaded, when it was downloaded
    • You can display an icon for the corresponding file types
    • You can reset the counter, or set the desired value

    However, there are some differences. Firstly, there is no button in the visual editor with which you can insert a shortcode. Or rather, there is a button, but in order to use it, you must first add a counter for the file in the plugin settings, and then with this button the ID of the counter will be added directly to the post. Secondly, there is only one template, and it will not be possible to display different information for different files. Among the advantages of statistics - it shows when the file was last downloaded, otherwise there are only disadvantages - no uploading to a csv file, no viewing of who downloaded (no IP), no distribution by date.

    But the icons are prettier (I later added them to the previous plugin). The result of his work looks like this:

    Also, when deleting a record from the database, it asks whether the file itself should be deleted or left. But in terms of the totality of its properties, I liked it less than the previous one - at least because the file must be inserted separately outside the post, however, it does not have any particular disadvantages - the choice between them is a matter of taste, the first has more options, more detailed statistics, the second - slightly more convenient (albeit poorer) statistics, and fewer opportunities.

    Heavy artillery went into action. The plugin is mostly Russified, and is just a download manager, not a counter. It is possible to limit the download speed and the number of downloads per person per day.

    But I would say that some of the features of this plugin are unnecessary, and those needed according to statistics are not enough. There are a lot of settings, download widgets, a complex synchronization system, a system for displaying mp3 tags, displaying flv files, organizing a mini-file storage, displaying all the files listed on the page at the beginning or end of the post, etc., etc.

    I don’t even want to show screenshots of all the settings.

    However, with all this, in order to display the template beautifully in the post, I had to edit the style file in it, reducing the width. Plus, in order to display the default template, you have to use the button after inserting the shortcode

    Enter the name of the template into the code manually. Some kind of conflict with the Russian name. By the way, it looks like this (I’ll give three options for templates):

    It counts - through a stump deck (well, or it doesn’t count more than one download from an IP, I don’t know). The statistics are a little less than completely similar to the plugin just discussed above.

    In general, I was left with the impression that he was healthy, but stupid. Suitable for some kind of file storage, and even then only if combined with some other plugin. I looked at it and took it down.

    Frankly speaking, when I read its description, I thought - this is it, what I need!

    Counter, password protection, button insertable shortcode, editable button, etc.

    And it looks like this (he cited two three templates used at once):

    However, in order to add a file, first you need to add a counter for it in the plugins. Secondly, there are practically no statistics at all.

    Thirdly, you cannot set the output to display the file size for the user. Fourthly, there is no limit on download speed, there is only password protection for the file. Templates cannot be edited. And a large inscription offering to buy the premium version for 45 bucks. Well, in general, you understand. Everything delicious is for money. Deactivated it and demolished it. And beautiful frames, buttons, etc. - I’ll write it down in the styles myself when I want.

    Summary

    Install in the standard way (by copying to the directory wp-content/plugins/download-monitor/, let it update, replace all icons with icons from the archive in the directory wp-content/plugins/download-monitor/img/filetype_icons/ and activate.

    In the future, if I get around to it, I’m thinking of putting the links into nice frames using css3, which I’ll most likely write about too. Stay tuned :)

    Upd. Now the author has reworked the WordPress Download Monitor plugin and created a completely different version from the original one. I tested it, but I liked it much less due to the fact that the template of the form of what the download link will look like is no longer so easily edited. The author decided that ready-made pre-installed views would be sufficient. For example, if in the downloads menu, then settings, select the desired view from six preset ones, click save

    Then when you choose the second option you get something like this:

    Those. on new version It won’t work to use the line I gave in the description, but you will need to write a special PHP file that would describe this output template. But the saddest thing is not even this - but the fact that this php file, if placed in the directory with the plugin, will be overwritten every time the plugin is updated. And if you put it in a directory with a theme, then when you change the theme (although this, of course, happens much less often). But in any case, writing it is a rather labor-intensive task, and so far I have no desire to do it. So the only plus of the updated plugin is

    I decided to see how many times one of my scripts was downloaded from the site. To do this, I decided to write a file download counter for the site. There are many implementations of this problem on the Internet, but nevertheless, check out my solution.

    The logic behind the download counter is quite simple. To implement it we will use my favorite ajax. We attach a call via ajax to the button when the clik event occurs php file counter. In php, the ajax request is processed and the total number of races is written to a text file. After a successful recording, a response is returned with a total download counter and the user is redirected to the link to download the file (the file is downloaded). This is such simple logic. Now let's start implementing it. Let's create a downloadable file test.zip in advance. Let's code the button and show the race counter.

    Download file Number of races:

    We created a button with id="btnSend" , we will display the counter in a span with id="countView" , and we will store a link to the downloaded file in the data-download attribute

    Now let's attach a click handler to the button. Here we will already use js and jquery. You can read about how to implement clik using jquery. But before installing the click handler, we will ajax access the count.php file, which will contain all the work of the counter. You can read more about ajax data transfer. This is necessary to output from the file where the counter writes the number of downloads already made and display them in a span with id="countView"

    /*get the current number of downloads*/ $(document).ready(function())( //prohibit caching of the ajax request //otherwise the counter will fail $.ajaxSetup((cache: false)); var html; $.ajax (( //how we will transfer data type: "GET", //where we will transfer url: "count.php", //what data we will transfer data: (flag: 2), //event after receiving a response from count.php success : function(data)( html=data; //display the current number of downloads $("#countView").html(html); ) )); /*attach an event to the download file button*/ var clickevent=false; //click test flag //click handler $("#btnSend").click(function())( if(!clickevent)( $.ajax(( //how we will transfer data type: "GET", //where we will transfer it url: "count.php", //what data are we passing data: (flag: 1), //event before sending ajax beforeSend: function())( //if the button was clicked then true clickevent=true; ), //event after receiving the response, //receive the data in data success: function(data)( //after completing the actions, we allow it again //to process the click on the button clickevent=false; html=data; //display a new counter $("#countView").html(html); //get the link from data-download //redirect to the download link, download the file window.location.href = $("#btnSend").data("download"); ) )); ) return false;//prohibit processing the click event )); ));

    To prevent the submit button from being pressed by mistake again, I introduced the clickevent flag into the script. Until the response from count.php returns with updated counter data, clicking on the button will be prohibited. I think the operation of the code after clicking on the button is more or less clear. After clicking on the download button, the data is transferred to the count.php file, where it is processed and updated counter data is returned, a redirect to the download link occurs and, accordingly, the file is downloaded.

    Let's now look at the heart of our script, namely the count.php file.

    Function clearInt ($date)( //reduce date to a non-negative number return abs((int)$date); ) if($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest") ( //check which flag was received if (clearInt($_GET["flag"]==1)) ( //open the file for reading $f=fopen("mycount.txt","a+"); //closes access to the file from other programs flock($ f,LOCK_EX); //get the counter value from the file $count=fread($f,100); //add the counter @$count++; //overwrite the file ftruncate($f,0); //write a new counter reading fwrite ($f,$count); //close the file fclose($f); //return the value echo $count; ) if(clearInt($_GET["flag"]==2)) ( $c=fopen(" mycount.txt","a+"); flock($c,LOCK_EX); $festc=fread($c,100); fclose($c); //return the value echo $festc; ) )

    Here I think the same thing, everything is simple. If flag 1 comes, then we rewrite the counter. If flag 2 comes, then data on the number of downloads is simply returned. Everything else, I think, is clear from the comments in the code.

    Joomla download counter

    I decided to attach a similar counter to one of my Joomla projects. In theory, of course, you need to write either a separate module, or integrate the code into the controller of the com content component, so that the counter data is written not to a file, but to the database and for each article separately. But there is no time for such development and I solved the problem more simply. I needed the counter for one page. I took the count.php file and transferred it to the Joomla template, which is currently connected (in the root of the site templates/your_template). Don't forget to insert the code defined("_JEXEC") or die at the very top of count.php. (this is for Joomla). We insert the download button into the page we create, and the js code can also be embedded in the page, or connected as a separate file. For example, I have it as a separate file (it is located in the js folder of the template). In the template itself, in the header, the connection occurs through code

    
    Top