Hi,
I've been looking into many options to try and create a progress indicator during file uploads to my server. It looks like lots of folks are using flush() to do this..I found a simple script to experiment with but with every script I find, it's not exactly clear where I place the code.. I have one php page that has my form and I'm posting to another php page that has my upload script. The following is the code I'm playing with..Anyone have any insight how to make this work? Currently when I include the code in the page with my upload script, I just get a blank page AFTER the upload completes. Any thoughts?
// Some HTML/CSS to spice up the spaces...
<html>
<head>
<style type="text/css"><!--
.pbar {
background: #EEE;
border: 1px solid #CCC;
margin: 1px;
height: 10px;
width: 10px;
}--></style>
</head>
<body>
<?php
// If the buffer is not set to 0, there's no need to call
// ob_start(), because the buffer is started already.
// You can test that by a call to ob_get_level();. Calling it
// again will cause a second level of buffering to start and
// the script won't work.
if (ob_get_level() == 0) {
ob_start();
}
echo str_pad('Loading... ',4096)."<br />\n";
for ($i = 0; $i < 25; $i++) {
echo '<span class="pbar"> </span>';
ob_flush();
usleep(700000);
}
ob_end_flush();
// Close it out...
?>
</body>
</html>
I've been looking into many options to try and create a progress indicator during file uploads to my server. It looks like lots of folks are using flush() to do this..I found a simple script to experiment with but with every script I find, it's not exactly clear where I place the code.. I have one php page that has my form and I'm posting to another php page that has my upload script. The following is the code I'm playing with..Anyone have any insight how to make this work? Currently when I include the code in the page with my upload script, I just get a blank page AFTER the upload completes. Any thoughts?
// Some HTML/CSS to spice up the spaces...
<html>
<head>
<style type="text/css"><!--
.pbar {
background: #EEE;
border: 1px solid #CCC;
margin: 1px;
height: 10px;
width: 10px;
}--></style>
</head>
<body>
<?php
// If the buffer is not set to 0, there's no need to call
// ob_start(), because the buffer is started already.
// You can test that by a call to ob_get_level();. Calling it
// again will cause a second level of buffering to start and
// the script won't work.
if (ob_get_level() == 0) {
ob_start();
}
echo str_pad('Loading... ',4096)."<br />\n";
for ($i = 0; $i < 25; $i++) {
echo '<span class="pbar"> </span>';
ob_flush();
usleep(700000);
}
ob_end_flush();
// Close it out...
?>
</body>
</html>