note 50624 added to function.flush
| From: | crmacd at yahoo dot com | Date: | Fri, 04 Mar 2005 23:28:31 +0000 |
| Subject: | note 50624 added to function.flush | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85953@lists.php.net to get a copy of this message | ||
I figured out a way to create a simple progress bar that is for the most part cross platform. Seeing
as I got my ideas from this site it's only share to give back to the community.
Note: Something interesting about browser buffering... you have to have the <html><body>
for Firefox and some other browsers to recognize items by their id in Javascript. So I recommend
using some sort of header function before calling this function.
<?php
function fn_progress_bar($intCurrentCount = 100, $intTotalCount = 100)
{
static $intNumberRuns = 0;
static $intDisplayedCurrentPercent = 0;
$strProgressBar = '';
$dblPercentIncrease = (100 / $intTotalCount);
$intCurrentPercent = intval($intCurrentCount * $dblPercentIncrease);
$intNumberRuns++;
if(1 == $intNumberRuns)
{
$strProgressBar = <<< BAR
<table width='50%' id='progress_bar' summary='progress_bar'
align='center'><tbody><tr>
<td id='progress_bar_complete' width='0%' align='center'
style='background:#CCFFCC;'> </td>
<td style='background:#FFCCCC;'> </td>
</tr></tbody></table>
<script type='text/javascript' language='javascript'>
function dhd_fn_progress_bar_update(intCurrentPercent)
{
document.getElementById('progress_bar_complete').style.width =
intCurrentPercent+'%';
document.getElementById('progress_bar_complete').innerHTML =
intCurrentPercent+'%';
}
</script>
BAR;
}
else if($intDisplayedCurrentPercent <> $intCurrentPercent)
{
$intDisplayedCurrentPercent = $intCurrentPercent;
$strProgressBar = <<< BAR
<script type='text/javascript' language='javascript'>
dhd_fn_progress_bar_update($intCurrentPercent);
</script>
BAR;
}
if(100 <= $intCurrentPercent)
{
$intNumberRuns = $intDisplayedCurrentPercent = 0;
$strProgressBar = <<< BAR
<script type='text/javascript' language='javascript'>
document.getElementById('progress_bar').style.visibility='hidden';
</script>
BAR;
}
echo $strProgressBar;
flush();
ob_flush();
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.flush.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50624
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50624&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50624&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50624&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50624&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50624&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50624&report=yes
Search -- http://master.php.net/manage/user-notes.php