PHP code example of stilliard / generic-loading-bar

1. Go to this page and download the library: Download stilliard/generic-loading-bar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stilliard / generic-loading-bar example snippets


use GLB\LoadingBar;
$loading = new LoadingBar;
$loading->step(); // each call is 1/100 (or whatever steps is set to)
$loading->set(40); // set a specific loaded %
$loading->complete(); // sets to 100 to mark as complete
$loading->reset(); // sets to 0 to start over

$loading = new LoadingBar([
    'codename' => 'my_loading_bar',
    'min' => 0,
    'max' => 100,
    'steps' => 150, // default: 100
    'dataHandler' => DBDataHandler::class, // default ProcessDataHandler
    'displayHandler' => HTMLDisplayHandler::class, // default EchoDisplayHandler
]);

$loading->step(); // each call is then 1/150 (or whatever steps is set to)

echo $loading->display(); // displays the html loading bar with auto refresh

echo $loading; // same as above

$totalProducts = count($products);
foreach ($products as $i => $product) {
    // fill in the range between 25% to 50% as the % of the total products handled so far. [index, total]
    $loading->calc([25, 50], [$i + 1, $totalProducts]);
}