Php download file with progress bar

File Downloader provides a standard progress bar dialog. However, sometimes it is more convenient to replace it with your own (for example, to customize it according to your site design). In order to perform this you should:

  1. hide the default progress dialog
  2. create your own progress bar
  3. make your progress bar displaying the actual state of downloading progress

Hiding Default Progress Dialog

To hide the standard progress dialog you should download files in background mode. To turn on this mode set the ShowProgressDialog property to false, like in the following sample:

JavaScript

<script language="javascript">
   var fd = new FileDownloaderWriter("FileDownloader1", 122, 44);
   //...other parameters...
   fd.addParam("ShowProgressDialog","false");
   //...other parameters...
   fd.writeHtml();
</script>

Adding Custom Progress Bar to Page

A custom progress bar may be implemented in several ways. For example, you can utilize a standard ActiveX component Progress Bar, or use the IMG element (or some other element) changing its width. Here, we use the DIV element:

html

<div style="width:200px; background-color:lightgrey">
   <div id="ProgressBar" style="width:0px; height:20px; background-color:blue; display:none;">
      <span id="ProgressBarText" style="width:200px; display:none; color:white; margin-left:90px;">
      </span>
   </div>
</div>

The following section shows how to change the element's width to display current download progress.

Changing Progress Bar State

To synchronize your progress bar with download process you can use the DownloadStep and Progress events. To utilize these events you should set the event handlers; the following sample shows how to do it:

JavaScript

<script language="javascript">
   var fd = new FileDownloaderWriter("FileDownloader1", 122, 44);
   //...other parameters...
   fd.addEventListener("Progress", "onProgress");
   fd.addEventListener("DownloadStep", "onDownloadStep");
   //...other parameters...
   fd.writeHtml();
</script>

The DownloadStep event allows to show/hide a progress bar. It fires in a certain steps of the download process. Each download step has its own predefined number; you get this number as the event parameter. We will handle the following steps:

  • the file download is about to start (6); it is a good moment to show the progress bar
  • the file download has been finished (7); you can to hide the progress bar in this moment

The Progress event gives you an ability to reflect the download progress. You can display progress of the current file download using the PercentCurrent event parameter and/or total download progress via the PercentTotal parameter. The last parameter, Index, is the number of currently downloading file.

The following sample makes the progress bar (the div element defined in the previous section) reflecting the current state of the total download progress:

JavaScript

<script type="text/javascript">
function onProgress(PercentTotal, PercentCurrent, Index){
   var progressBar = document.getElementById("ProgressBar");
   var progressBarText = document.getElementById("ProgressBarText");        
   //Max width of progress bar 
   var progressBarWidth = 200;
   //Show download progress 
   //Set width of progress bar 
   progressBar.style.width = Math.round(PercentTotal/100*progressBarWidth) + "px";
   //Set percentage text
   progressBarText.innerHTML = PercentTotal + "&#37;";
}

function onDownloadStep(Step) {
   var progressBar = document.getElementById("ProgressBar");
   var progressBarText = document.getElementById("ProgressBarText");        
   switch(Step)
   {
      case 6: // File download is about to start
         //Show zero width progress bar
         progressBar.style.display = "block";
         progressBarText.style.display = "block";
         progressBar.style.width = "0px";
         break;
      case 7: // File download has been finished
         //Hide progress bar
         progressBar.style.display = "none";
         progressBarText.style.display = "none";
         break;
   }
}       
</script>

PHP, HTML, CSS, JQuery, AJAX, and JavaScript were used to create the Progress Bar in PHP. When uploading any file type to our system or website, we use this Dynamic Progress Bar in PHP.

We’ll construct a File Upload Progress Bar In PHP Example in File Upload With Progress Bar In PHP. We have a file input field and a progress bar in the example below. If the Upload With Progress Bar PHP is already complete, the progress bar will be displayed. In order to perform this effectively, we must also use the jQuery and AJAX functions.

In this article, you will learn how to make a progress bar in PHP in a simple and quick manner. Also, the scripts and processes in this tutorial are simple to understand, making it suitable for novices or students.

Why Progress Bar PHP Script is important?

Why Progress Bar PHP Script is important

A Progress Bar In PHP can be used to show the status of any PHP function that is running in the background. I’ll show you how to create a real-time progress bar to monitor the status of your PHP script running on the server using only pure PHP code and javascript.

What is the advantages of Progress Bar in PHP Source Code?

What is the advantages of Progress Bar in PHP Source Code

A progress bar helps them to quickly access information that was previously entered but is no longer accessible. If you don’t let users skip around, they’ll either push the back button on your form several times (causing extra friction) or utilize their browser’s Back button.

How to make Progress Bar using PHP?

How to make Progress Bar using PHP

Just simply follow the steps below on how to make Progress Bar using PHP. the procedure will be found below this article and source code and ready to download file is ready.

About the project

Any PHP function executing in the background can have a progress bar to show its status. I’ll teach you how to use basic pure PHP code and javascript to construct a real-time progress bar to monitor the status of your PHP script running on the server.

Project Details and Technology

Project Name: Progress Bar in PHP Code Free Download
Abstract This PHP project for a Progress Bar in PHP Code Free Download focuses on dealing when user upload file then progress bar will execute to give user friendly interface.
Language/s Used: PHP
PHP version (Recommended): 5.6.3, 7.4.12
Database: N/A
Type: Web Application
Developer: Source Code Hero
Updates: 0

Before you begin using this Progress Bar In PHP, make sure you have sublime or another PHP and MySQL platform installed on your computer.

Steps how to run the system

Time needed: 5 minutes.

  • Step 1: Download Source Code

    To get started, find the downloaded source code file below and click to start downloading it.

    Php download file with progress bar

  • Step 2: Extract File


    Navigate to the file’s location when you’ve finished downloading it and right-click it to extract it.

    Php download file with progress bar

  • Step 3: Copy Project Folder


    The project folder should now be copied to C:xampphtdocs.

    Php download file with progress bar

  • Step 4: Open Xampp


    After that, use xampp to start apache and mysql.

    Php download file with progress bar

  • Step 5: Execute Project

    Finally, navigate to localhost/PROJECT_NAME URL.

Download Source Code Below

  • Progress Bar In Java With Source Code
  • Bar Graph in PHP with Source Code

Inquiries

Please leave a comment below if you have any questions or comments about the project.