How to install download counter in my code

Forum for you who has PHP installation issues

Moderators: egami, macek, gesf

Post Reply
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Tue Mar 31, 2020 9:33 am

I have a download section in my index.php that I'd like to add a download counter to but have no idea how to accomplish this. The existing code works perfectly but I'd like to know how many times the file is downloaded. Would prefer not to use a database.

Code: Select all

<!--  DOWNLOAD -->
<div id="download" class="stylized">
    <div "myform">
    <div class="container">
        <div class="row">
            <div class="download">
                <br /><br>
                <h1><center>FoxClone Download Page</center></h1>
                   <?php
                    $files = glob('download/*.iso');
                    $file = $files[count($files) -1];
                    $info = pathinfo($file);
                    $filename =  basename($file);
                    $md5file = md5_file($file);
                   ?>

                    <div class="container">
                        <div class="divL">                       
                            <h3>Get the "<?php echo "{$filename}";?>" file (approx. 600MB)</h3>
                        <center>  <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a> </center><br />
                            <h3 style="margin-bottom: 0.5rem;">The MD5sum for "<?php echo "{$filename}";?>" is "<?php echo "{$md5file}";?>  

<br>
Thanks in advance,
Larry
If you don't know what you don't know, ask an expert.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Tue Mar 31, 2020 10:24 am

How are you expecting to get/see the result?
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Tue Mar 31, 2020 10:32 am

My idea was to read a text file, increment +1, write back to the text file and display the new number in a text box. Is there an easier way?
If you don't know what you don't know, ask an expert.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Tue Mar 31, 2020 11:29 am

My idea was to read a text file, increment +1, write back to the text file and display the new number in a text box.
Why did you change your mind?
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Tue Mar 31, 2020 11:36 am

I haven't, just don't know how to code it.

After thinking about it some more, a database on the backend might be more useful in the long run. Until 20 years ago, I wrote front-end software for industrial databases. I'll need to brush-up on my sql queries and foreign-keys first.
If you don't know what you don't know, ask an expert.
Post Reply