[Solved] Status message before entire page load

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

[Solved] Status message before entire page load

Post by Burrito »

I have a situation where users will be uploading files to our codification system here and some of them will then be uploaded to our streaming server (offiste) using ftp. Some of these files are friggin' ginormous so I would like to indicate to the users half way through that their file is still being worked on (as soon as the upload is complete to our server and prior to the upload to the offsite streaming server).

I tried the code below, but it doesn't display anythign until the whole process is done. I'm thinking I need some kind of ob_ something or other here, but not sure what exactly...please advise:
<?if(isset($message)){ echo "<div class=\"red\" align=\"center\">".$message."</div>"; } else {
if(
$initftp){
echo
"<span id=\"rmftp\">Your file has been uploaded to the LearningPathways server, now uploading to the PlayStream server....please wait</span>";
$conn_id = ftp_connect("ftp.ftpserver.com")
or die(
"could not connect to playstream.com");
$login_result = ftp_login($conn_id, "myUser", "myPass")
or die(
"could not log in to playstream.com");
$upload = ftp_put($conn_id, "lp/".$_FILES["bob"]["name"], "datafiles/".$dir.$_FILES["bob"]["name"], FTP_BINARY)
or die(
"could not upload to playstream.com");
ftp_close($conn_id);
echo
"<script>
document.getElementById('rmftp').innerHTML = \"Upload Complete<br>\";
</script>"
;
}
// end if for need to ftp rm files to playstream server...burrito
?>
thanks...

Burr
Last edited by Burrito on Mon Mar 07, 2005 5:01 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

flush()
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

I have an animated progress bar hidden in a div until the submit is pressed. I make the div visible and process the form.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well the hidden div would work, but I want this two step process to show each stage of the process.

I got it working perfectly by having a hidden iframe on my submit page that I pass the vars to through the url. the iframe does the ftp upload while the parent page shows what is happening. As soon as the iframe is done processing the ftp upload, it changes a span using innerHTML to indicate the file is totally done....works like a champ.

Burr
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

I wonder if its possible to simply flush out a javascript line which would be a div.innerHTML change to show each step of the process? This way you could have the page show, then do the processing of the upload while showing the progress
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ok, I thought I had this one solved...but I just ran into a stumbling block. I just tried it with a very large file and it doesn't change the span on my parent page to indicate the file is done...nor does it do the alert...see code below:
<?
require_once('includes/dbInteract.php');
    
tt_db_connect();

$conn_id = ftp_connect("ftp.playstream.com")
            or die(
"could not connect to playstream.com");
        
$login_result = ftp_login($conn_id, "username", "password")
            or die(
"could not log in to playstream.com");
        
$upload = ftp_put($conn_id, $_GET['t'], $_GET['s'], FTP_BINARY)
            or die(
"could not upload to playstream.com");
        
ftp_close($conn_id);
        if(
$upload){
        echo
"<script>
        alert('File Upload Process Complete');
        parent.document.getElementById('rmftp').innerHTML = \"Upload Complete<br>\";
        parent.clearInterval(parent.id);
        parent.document.getElementById('rmftp').style.color = '';
        parent.document.getElementById('done').style.display = 'block';
    </script>"
;
        }
// end if for show upload status...burrito
?>
it works fine with smaller files, but I'm thinking there is some kind of timeout setting I need to set for the echo statement to not die if the timeout time has been met....


EDIT: the file is being uploaded just fine, just the js isn't working right....

any suggestions?

thx,

Burr
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

set_time_limit(0) got me there...
Post Reply