Create PHP/MySQL Download Counter for your Website
Today we are going to implement a download counter tool for your PHP/MySQL web page. Here we used syntax of HTML, CSS, PHP and MySQL. Above the file name, we have introduced the download now button to download the file. Once you download the file, the counter shows the downloaded times in numerical value.
‘Download Now’ button is decorated by CSS and other descriptions like filename and the download times tabs are also decorate with CSS syntax. When you press the download button, the counter value goes into database and output will give as how many time the file has been downloaded. Let’s go through the .php files, css and folders which you need to implement the download counter page.
Making the directories.
Create a folder in www directory (I’m using WAMP Server). In that folder create a folder called ‘files’. This is the location where you are going to save the files which has to be downloaded through the web page.
I have created a text file name rename it as > test_download_file (Make sure to put the same name into the database and with the correct extension. Here we will use ‘test_download_file.txt)
You have to copy below file into files folder to work the download properly. And make a text file following by below name as ‘text_download_file’. This name will appear under the download button.
Click on the above link to download the required file to continue. After downloading the file you need to make other PHP and CSS files as follows.
- configuration.php
- connect.php
- download.php
- home.php
- styles.css
Creating the Database
Rather creating a fresh database, visit here to download download.sql file to import. Otherwise you can create a fresh database and enter data as you required.
My database name is ‘download_counter’. I have created a table called ‘download’. In that table I used below columns.
- (id) The downloadable file will show under this id number. EX: If we want to get the 10th download file which we have inserted to our database and copy to files directory, we can use id as 10.
- (filename) This file name should equal to the file which you previously copied into files directory.
- (downloads) This column will count the downloaded times.
If you have any doubts regards to this PHP MySQL web tutorial, don’t hesitate to ask and comment below. We will reply you with answers and also your comments will encourage us to do the next tutorial.
You can download relevant files from our official download center. Visit for more info: Download Center
Cheers!
Post a Comment