Problem with ftp_nb_get and javascript function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cristian

    #1

    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.getEle mentById("pippo ").value=num+": "+num2+"."+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
  • Daniel Tryba

    #2
    Re: Problem with ftp_nb_get and javascript function

    Cristian <cristiancaracc iolo@nospammeth osystem.it> wrote:
    [snip code][color=blue]
    > 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.[/color]

    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).

    Comment

    • Markus Ernst

      #3
      Re: Problem with ftp_nb_get and javascript function

      Cristian wrote:[color=blue]
      > 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.getEle mentById("pippo ").value=num+": "+num2+"."+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?[/color]

      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


      Comment

      • Cristian

        #4
        Re: Problem with ftp_nb_get and javascript function

        Markus Ernst ha scritto:[color=blue]
        > Cristian wrote:
        >[color=green]
        >>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.getEle mentById("pippo ").value=num+": "+num2+"."+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?[/color]
        >
        >
        > 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.
        >[/color]
        thanks all.
        I have create a new javascript page that I have include in the while cycle.
        Now all works fine.
        Bye.
        Cristian.

        Comment

        Working...