tags:

views:

56

answers:

4

Hello people,

I have been trying to get the following code working.

It's a progress bar trick which uses ob_get_clean() function.

Don't know why but this script just don't work!

Only the initial percent - 1% comes up and nothing after that.

<?php  
error_reporting(8191);  
function flush_buffers(){  
    @ob_end_flush();  
    @ob_flush();  
    @flush();  
    @ob_start();
} 
$ini    =   2;
echo '<script>document.getElementById(\'lpt\').style.width=\'1%\';</script><br>';  
for($i=1;$i<=100;$i++)  {
            $k=$ini-1;
            $str=str_replace("width=\'$k%\'","width=\'$i%\'",ob_get_clean());           
            $ini++;
            echo $str;
            flush_buffers();
}

?>

+2  A: 

You can't 'retract' output text after you've sent it to the client. It merely gets appended.

Delan Azabani
A: 

You can't do progress bar in PHP, you must write in eg. JavaScript, and only echo with PHP. You can't do that because PHP is server-side language and any loading is performing on client-side because server don't loads anything then loading script you must have in client-side language.

Svisstack
+1  A: 

It would not work as you are trying to mix server and client side code. PHP Code on the client side would not work. You will need to build the whole progress bar using javascript itself.

pinaki
i would think that this is possible using flex but i am not very sure.
pinaki
+1  A: 

What @Delan says: You can't "take back" and edit output that has already been sent to the client. You would have to output a completely new <script> snippet for every movement of the percentage bar.

Pekka