Problem with ftp_nb_get and javascript function

This is a discussion on Problem with ftp_nb_get and javascript function within the PHP Language forums, part of the PHP Programming Forums category; Hi all, When I download a file with ftp_nb_get, I'd like to show the elapsed time and so I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2005
Cristian
 
Posts: n/a
Default Problem with ftp_nb_get and javascript function

Hi all,
When I download a file with ftp_nb_get, I'd like to show the elapsed
time and so I had insert this javascript function in my php page
<SCRIPT>
function scrivi(num, num2, num3) {
document.getElementById("pippo").value=num+":"+num 2+"."+num3;
}
</SCRIPT>

that I call when I download the file:

while ($ret == FTP_MOREDATA)
{
$ss += 1;
if ($ss == 60) {$ss = 0; $mm += 1;}
if ($mm == 60) {$mm = 0; $hh += 1;}

print "<SCRIPT> scrivi($hh,$mm,$ss); </SCRIPT>";
$ret = ftp_nb_continue($conn_id);
}

Problem: The download is OK, but the while cycle doesn't finish
correctly because a loop is created. If I delete the javascript line,
the while cycle finish correctly.
Can someone help me?
Thanks
Cristian

P.S. Excuse me for my horrible English
Reply With Quote
  #2 (permalink)  
Old 04-17-2005
Daniel Tryba
 
Posts: n/a
Default Re: Problem with ftp_nb_get and javascript function

Cristian <cristiancaracciolo@nospammethosystem.it> wrote:
[snip code]
> Problem: The download is OK, but the while cycle doesn't finish
> correctly because a loop is created. If I delete the javascript line,
> the while cycle finish correctly.


What are you trying to do? It seems to me you are mixing clientside code
with serverside code and expect that to work together? You do remember
that when the clientside code isn't executed untill the serverside part
has long been finished (in most cases and I don't see why that would be
any different here).
Reply With Quote
  #3 (permalink)  
Old 04-17-2005
Markus Ernst
 
Posts: n/a
Default Re: Problem with ftp_nb_get and javascript function

Cristian wrote:
> Hi all,
> When I download a file with ftp_nb_get, I'd like to show the elapsed
> time and so I had insert this javascript function in my php page
> <SCRIPT>
> function scrivi(num, num2, num3) {
> document.getElementById("pippo").value=num+":"+num 2+"."+num3;
> }
> </SCRIPT>
>
> that I call when I download the file:
>
> while ($ret == FTP_MOREDATA)
> {
> $ss += 1;
> if ($ss == 60) {$ss = 0; $mm += 1;}
> if ($mm == 60) {$mm = 0; $hh += 1;}
>
> print "<SCRIPT> scrivi($hh,$mm,$ss); </SCRIPT>";
> $ret = ftp_nb_continue($conn_id);
> }
>
> Problem: The download is OK, but the while cycle doesn't finish
> correctly because a loop is created. If I delete the javascript line,
> the while cycle finish correctly.
> Can someone help me?


Maybe in your special case it might get to work like this:

while ($ret == FTP_MOREDATA)
{
$ss += 1;
if ($ss == 60) {$ss = 0; $mm += 1;}
if ($mm == 60) {$mm = 0; $hh += 1;}

// Change: add quotes to hand over values as strings, not integers
print "<SCRIPT> scrivi('$hh','$mm','$ss'); </SCRIPT>";
$ret = ftp_nb_continue($conn_id);

// Change: Send data to client at the end of the loop cycle
flush();
}

Anyway I am not sure if it works at all. So, as Daniel Tryba pointed out, it
is for sure a better idea not to try mixing up server side and client side
code. You could get the same effect like this:
- Write a page with the time counting function written totally in
Javascript. Display this page when FTP transfer begins.
- When FTP transfer is done, display new page.

--
Markus


Reply With Quote
  #4 (permalink)  
Old 04-18-2005
Cristian
 
Posts: n/a
Default Re: Problem with ftp_nb_get and javascript function

Markus Ernst ha scritto:
> Cristian wrote:
>
>>Hi all,
>>When I download a file with ftp_nb_get, I'd like to show the elapsed
>>time and so I had insert this javascript function in my php page
>><SCRIPT>
>>function scrivi(num, num2, num3) {
>> document.getElementById("pippo").value=num+":"+num 2+"."+num3;
>>}
>></SCRIPT>
>>
>>that I call when I download the file:
>>
>>while ($ret == FTP_MOREDATA)
>> {
>> $ss += 1;
>> if ($ss == 60) {$ss = 0; $mm += 1;}
>> if ($mm == 60) {$mm = 0; $hh += 1;}
>>
>> print "<SCRIPT> scrivi($hh,$mm,$ss); </SCRIPT>";
>> $ret = ftp_nb_continue($conn_id);
>> }
>>
>>Problem: The download is OK, but the while cycle doesn't finish
>>correctly because a loop is created. If I delete the javascript line,
>>the while cycle finish correctly.
>>Can someone help me?

>
>
> Maybe in your special case it might get to work like this:
>
> while ($ret == FTP_MOREDATA)
> {
> $ss += 1;
> if ($ss == 60) {$ss = 0; $mm += 1;}
> if ($mm == 60) {$mm = 0; $hh += 1;}
>
> // Change: add quotes to hand over values as strings, not integers
> print "<SCRIPT> scrivi('$hh','$mm','$ss'); </SCRIPT>";
> $ret = ftp_nb_continue($conn_id);
>
> // Change: Send data to client at the end of the loop cycle
> flush();
> }
>
> Anyway I am not sure if it works at all. So, as Daniel Tryba pointed out, it
> is for sure a better idea not to try mixing up server side and client side
> code. You could get the same effect like this:
> - Write a page with the time counting function written totally in
> Javascript. Display this page when FTP transfer begins.
> - When FTP transfer is done, display new page.
>

thanks all.
I have create a new javascript page that I have include in the while cycle.
Now all works fine.
Bye.
Cristian.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0