Copy data between files

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

    #1

    Copy data between files

    How do I copy data from one file to another? from $_SESSION['fname'] to
    "fname"

    datafile.php has

    fname: $_SESSION['fname'];
    lname: $_SESSION['lname'];

    I would like to automatically copy the data to

    second.js

    var fname = "fname";
    var lname = "lname";

    to be used in JavaScript.

    I am familiar with
    $contents = file_get_conten ts($filename);

    and I know how to copy files but not data inside of the file.

    Thanks for the help.

    Ken




  • Erwin Moller

    #2
    Re: Copy data between files

    Ken wrote:
    [color=blue]
    > How do I copy data from one file to another? from $_SESSION['fname'] to
    > "fname"
    >
    > datafile.php has
    >
    > fname: $_SESSION['fname'];
    > lname: $_SESSION['lname'];
    >
    > I would like to automatically copy the data to
    >
    > second.js
    >
    > var fname = "fname";
    > var lname = "lname";
    >
    > to be used in JavaScript.
    >
    > I am familiar with
    > $contents = file_get_conten ts($filename);
    >
    > and I know how to copy files but not data inside of the file.
    >
    > Thanks for the help.
    >
    > Ken[/color]


    Hi Ken,

    Have a look at:


    You will find a few examples and related functions over there.
    It is not difficult.
    1) Open a filehandle for the file to read.
    2) Open a filehandle to the file to write to.
    3) Walk though the first file and write stuff you want in the second file to
    the second handle.
    4) close both filehandles.

    Good luck.
    Regards,
    Erwin Moller

    Comment

    • Daniel Tryba

      #3
      Re: Copy data between files

      Ken <kkrolski@wi.rr .com> wrote:[color=blue]
      > How do I copy data from one file to another? from $_SESSION['fname'] to
      > "fname"
      >
      > datafile.php has
      >
      > fname: $_SESSION['fname'];
      > lname: $_SESSION['lname'];
      >
      > I would like to automatically copy the data to
      >
      > second.js
      >
      > var fname = "fname";
      > var lname = "lname";[/color]

      You don't actually want to you copy that! fname and lname strike me like
      lastname and firstname variables, so they are dependend on the user ->
      session data.

      So just serve the javascript by using php and you can use the session
      data to dynmically set the values of [lf]name (don't forget to set hte
      correct mimetype else strange things can happen).

      Comment

      • Chung Leong

        #4
        Re: Copy data between files

        "Ken" <kkrolski@wi.rr .com> wrote in message
        news:yuTXd.81$h u3.65@twister.r dc-kc.rr.com...[color=blue]
        > How do I copy data from one file to another? from $_SESSION['fname'] to
        > "fname"
        >
        > datafile.php has
        >
        > fname: $_SESSION['fname'];
        > lname: $_SESSION['lname'];
        >
        > I would like to automatically copy the data to
        >
        > second.js
        >
        > var fname = "fname";
        > var lname = "lname";
        >
        > to be used in JavaScript.
        >
        > I am familiar with
        > $contents = file_get_conten ts($filename);
        >
        > and I know how to copy files but not data inside of the file.
        >[/color]

        Just do something like

        echo <<<JS
        <script>
        fname = {$_SESSION['lname']};
        lname = {$_SESSION['lname']};
        </script>
        JS;

        Linked in Javascript code run in the same context as the HTML page. You
        don't need to set the variables in the .js file itself.


        Comment

        Working...