Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flush()?? 1

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
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">&nbsp;</span>';
ob_flush();
usleep(700000);
}
ob_end_flush();

// Close it out...
?>
</body>
</html>
 
i think that's logical as the new page is not called until after the upload is completed.

if you want a progress indicator (or a wait page) for file uploads then i'd suggest you consider either:

1. native javascript: change the page contents to a waiting page before you submit the form with the file upload
2. ajax: this could be quite neat as you can get hold of the filesize in javascript and use ajax (javascript) to feed chunks to the server.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top