Bayesean Blog - Desktop, Mobile and IOT Developer Blog

PHP Downloader using Countdown timer

Posted on 17th Mar 2017 in Bootstrap 4, CSS


This is an update of the original blog updated from bootstrap 3 to use bootstrap 4 and with a smooth progress bar adjusted in the JavaScript code. The viewer has been removed and replaced with the above gif.


Project Scope

This project scope came about when a comment was received asking how to use a seconds timed delay. So I put a blog together on this. The original progress bar was  jerky in nature and did not look professional.

While updating the blog to Bootstrap 4, the scope required a smooth progressbar showing the seconds counting down.

  • Must not show the download button immediately to prevent non-human downloading.
  • Must keep the user knowledgeable as to what is happening by adding a count-down timer linked to a progress bar.
  • Must flow automatically.
  • Must immediately download the file that was selected on the click of the button that became visible after completion of the progress bar.

Coding Difficulty

Medium. Good knowledge of Javascript/Ajax and PHP required would help.


Bootstrap 4 Framework –download  here.

PHP 5.6 +   download  here .

Downloader.php  -  A PHP Library (A  free to use file download library created by Jack Mason )

This is included in the included Download below.

JQuery – download from here or visit the website





This file contains the visual element of a drop down box to select the file to download.


This file contains the visual download progress bar and button to download the file.


This file is called by the download button and processes the file to download.


This holds all the mime information and allows any type of file to be downloaded.


To show and hide classes, the class “hidden” is no longer for bootstrap 4. This is replaced with class = ”d-none” to perform the same functionality.

The main action in the blog is within the interval of the JavaScript code. To use seconds change for interval timing results in an un-smooth progress bar change. So the trick is to update the width of the progress bar at 10 times the speed of a second. This allows the progress bar to update smoothly. Should you try to update in milliseconds, the bootstrap 4 progress bar does not react correctly as it is not designed to update at that frequency.

Whilst the progress bar (width) is updating at 10 times the speed, the second value is updated when the ‘proglevel’ (check code below) value equals the value of a second then this triggers the title in the progress bar to update the seconds value.

To adjust the delay in seconds, change only the variable ‘seconds = 20’ to for example ‘seconds = 40’.

Herewith is a snippet of the main JavaScript function that controls the progress bar’s changes.

You can download the full code for the project at the end of the blog


<script type="text/javascript">
     var countdownElement = document.getElementById('progress-bar'),
      seconds = 20, // changes the seconds delay in the progress bar
      second = 0,
      proglevels = seconds*10;
      proglevel = 0;

    interval = setInterval(function() {
    var  varinfo = 'Downloading in ' + (seconds - second) + ' seconds';
     width = (100/proglevels)*(proglevels-(proglevels-proglevel));
     document.getElementById("progress-bar").innerHTML =varinfo ;
     if (second >= seconds) {
           var varinfo2 = " Click Download Button to Download the File";
             document.getElementById("progress-bar").innerHTML =varinfo2;
       if ((proglevel/10)== (second + 1)){ 




Licence is MIT.


Download the code from the GITHUB repository.


Download Code




John S      Commented   3 years ago Reply

Great implementation. Can use this straight in my current work

Andy      Commented   3 years ago Reply

Thumbs up

private      Commented   3 years ago Reply

Hey Do you have code for multi-file upload that works similar.

Admin      Replied    Moderator   3 years agoReply

Hi , I will work on a small blog to include multi-upload and a drag n drop option which seems to be the main trend for multi-file uploading.

Add a Comment


Recent News

Delphi Delimited String to Fields
Delphi A Professional VCL DBGrid Part Four
Delphi A Professional VCL DBGrid Part Three
Delphi A Professional VCL DBGrid Part Two
Delphi A Professional VCL DBGrid Part One
Delphi VCL Buttons in DBGrid
Two Helper Apps for Delphi LibUSB
Delphi Libusb Library Introduction


Bootstrap 4
Delphi VCL
Delphi FMX
Bootstrap 3
XE4>Delphi > XE4
Delphi < XE4


August 2019

Delphi Delimited String to Fields

June 2019

Delphi A Professional VCL DBGrid Part Four

May 2019

Delphi A Professional VCL DBGrid Part Three

April 2019

Delphi A Professional VCL DBGrid Part Two

March 2019

Delphi A Professional VCL DBGrid Part One

November 2018

Delphi VCL Buttons in DBGrid

October 2018

Two Helper Apps for Delphi LibUSB

September 2018

Delphi Libusb Library Introduction

August 2018

Delphi Object directly to a Json string in a REST Client
Delphi using Environment Variables in your App

July 2018

Delphi FMX Leaflet Plotter using OSM Maps

June 2018

C2PAS32 Convertor Application
C to Delphi Open Source Convertors Shootout
Delphi command-line programs with DOSCommand

May 2018

Delphi PDF Embedded viewer with PDF.js

March 2018

Delphi FMX - Changing TCharacter to TCharHelper
Make Your Delphi App POP using Javascript!

January 2018

Delphi FMX Dashboard using Chart.JS
Delphi FMX Form Docking

December 2017

PHP Slim REST Server & Delphi Auth Part 5

November 2017

Delphi FMX REST Client App Part 4

October 2017

Delphi VCL REST Pricing Client App Part 3

September 2017

Delphi REST VCL Client Basic Auth Part 2B

August 2017

Delphi REST Client Part 2A
PHP PDO REST Server Part 1

July 2017

PHP REST Server and Delphi Client Intro

June 2017

Delphi SQLite Encryptor-Decryptor Tool
Updating Applications Manifest using Delphi

May 2017

Create a Visual IP Address Geolocation with PHP

March 2017

PHP Downloader using Countdown timer
PHP File Downloader from a Inbox Selection

February 2017

Javascript Image-File Uploader with ThumbViewer

January 2017

Morris Charts and PHP-PDO

December 2016

CSS to create a functional Toggle Button