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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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). |
|
|||
|
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 |
|
|||
|
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. |