writing files to a choosen directory

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

    writing files to a choosen directory


    Hello
    I have the following code which changes directory, creates a file and then
    writes rows to it. It works fine except the file is created in the folder
    the php script is in instead of the download directory specified in the
    scrip. Can anyone see where I have gone wrong
    Also I want to show the question Index and Question on screen as a list.
    Ive put

    echo $nt['QuestionIndex'], $nt['Question'];

    here <<<<<<<<<<<<<<< < in the script
    but it doesnt work, any ideas?

    Ian

    *************** ***************
    $query= "SELECT * FROM Questions WHERE NCIndex='".$_SE SSION['NCI']."' AND
    QuestionIndex IN (".join(",", $_SESSION['questions']).") ORDER BY
    QuestionIndex";

    $rt=mysql_query ($query)
    or die(mysql_error ());
    echo mysql_error();

    if (ftp_chdir($con n_id, "../htdocs/Downloads")) {
    echo "Current directory is now: " . ftp_pwd($conn_i d) . "\n";

    }else {
    echo "Couldn't change directory\n";
    }
    $fp = fopen('ptq'.$_S ESSION['username'].time().'.txt', 'w')
    or die('Could not open the text file for writing');
    while ($nt = mysql_fetch_arr ay($rt, MYSQL_NUM)){

    $line = "INSERT INTO tQuestions VALUES ('', '" .
    implode("', '", $nt) .
    "');\r\n";
    fwrite($fp, $line);
    echo $nt['QuestionIndex'], $nt['Question']; <<<<<<<<<<<<< <<
    }
    fclose($fp);

    *************** ************


  • Kimmo Laine

    #2
    Re: writing files to a choosen directory

    "Ian Davies" <iandan.dav@vir gin.net> kirjoitti
    viestissä:Lgpbf .9822$Ua6.3680@ newsfe6-win.ntli.net...[color=blue]
    >
    > Hello
    > I have the following code which changes directory, creates a file and then
    > writes rows to it. It works fine except the file is created in the folder
    > the php script is in instead of the download directory specified in the
    > scrip. Can anyone see where I have gone wrong
    > Also I want to show the question Index and Question on screen as a list.
    > Ive put[/color]


    Your code opens an ftp connection, but it doesn't write to it. it does
    change the directory in the ftp-connection, but that is irrelevant if you
    are writing to a local file. Just change the code to $fp =
    fopen('../htdocs/Downloads/ptq'.$_SESSION['username'].time().'.txt', 'w'));
    and remove the ftp-stuff, and you're good to go.

    --
    SETI @ Home - Donate your cpu's idle time to science.
    Further reading at <http://setiweb.ssl.ber keley.edu/>
    Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>


    Comment

    • Ian Davies

      #3
      Re: writing files to a choosen directory

      That gives the following message

      Warning: fopen(../htdocs/Downloads/ptqiandandav113 1304863.txt): failed to
      open stream: No such file or directory in
      e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\notify .php on line 43
      Could not open the text file for writing

      but the directory does exist

      Is the file local if its in a directory on my hosts server ?

      "Kimmo Laine" <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id> wrote in
      message news:dkljrq$3il $1@phys-news1.kolumbus. fi...[color=blue]
      > "Ian Davies" <iandan.dav@vir gin.net> kirjoitti
      > viestissä:Lgpbf .9822$Ua6.3680@ newsfe6-win.ntli.net...[color=green]
      > >
      > > Hello
      > > I have the following code which changes directory, creates a file and[/color][/color]
      then[color=blue][color=green]
      > > writes rows to it. It works fine except the file is created in the[/color][/color]
      folder[color=blue][color=green]
      > > the php script is in instead of the download directory specified in the
      > > scrip. Can anyone see where I have gone wrong
      > > Also I want to show the question Index and Question on screen as a list.
      > > Ive put[/color]
      >
      >
      > Your code opens an ftp connection, but it doesn't write to it. it does
      > change the directory in the ftp-connection, but that is irrelevant if you
      > are writing to a local file. Just change the code to $fp =
      > fopen('../htdocs/Downloads/ptq'.$_SESSION['username'].time().'.txt',[/color]
      'w'));[color=blue]
      > and remove the ftp-stuff, and you're good to go.
      >
      > --
      > SETI @ Home - Donate your cpu's idle time to science.
      > Further reading at <http://setiweb.ssl.ber keley.edu/>
      > Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>
      >
      >[/color]


      Comment

      • Ian Davies

        #4
        Re: writing files to a choosen directory

        OK
        I done it
        I didnt need the htdocs bit in the path
        Ian

        "Ian Davies" <iandan.dav@vir gin.net> wrote in message
        news:RNsbf.1037 8$Ua6.8826@news fe6-win.ntli.net...[color=blue]
        > That gives the following message
        >
        > Warning: fopen(../htdocs/Downloads/ptqiandandav113 1304863.txt): failed to
        > open stream: No such file or directory in
        > e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\notify .php on line[/color]
        43[color=blue]
        > Could not open the text file for writing
        >
        > but the directory does exist
        >
        > Is the file local if its in a directory on my hosts server ?
        >
        > "Kimmo Laine" <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id> wrote in
        > message news:dkljrq$3il $1@phys-news1.kolumbus. fi...[color=green]
        > > "Ian Davies" <iandan.dav@vir gin.net> kirjoitti
        > > viestissä:Lgpbf .9822$Ua6.3680@ newsfe6-win.ntli.net...[color=darkred]
        > > >
        > > > Hello
        > > > I have the following code which changes directory, creates a file and[/color][/color]
        > then[color=green][color=darkred]
        > > > writes rows to it. It works fine except the file is created in the[/color][/color]
        > folder[color=green][color=darkred]
        > > > the php script is in instead of the download directory specified in[/color][/color][/color]
        the[color=blue][color=green][color=darkred]
        > > > scrip. Can anyone see where I have gone wrong
        > > > Also I want to show the question Index and Question on screen as a[/color][/color][/color]
        list.[color=blue][color=green][color=darkred]
        > > > Ive put[/color]
        > >
        > >
        > > Your code opens an ftp connection, but it doesn't write to it. it does
        > > change the directory in the ftp-connection, but that is irrelevant if[/color][/color]
        you[color=blue][color=green]
        > > are writing to a local file. Just change the code to $fp =
        > > fopen('../htdocs/Downloads/ptq'.$_SESSION['username'].time().'.txt',[/color]
        > 'w'));[color=green]
        > > and remove the ftp-stuff, and you're good to go.
        > >
        > > --
        > > SETI @ Home - Donate your cpu's idle time to science.
        > > Further reading at <http://setiweb.ssl.ber keley.edu/>
        > > Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...