By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,608 Members | 1,925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,608 IT Pros & Developers. It's quick & easy.

Problem with ftp_nb_get and javascript function

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Cristian <cr****************@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).
Jul 17 '05 #2

P: n/a
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
Jul 17 '05 #3

P: n/a
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.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.