How to create & write a file on ftp by PHP

Discussion in 'PHP' started by KingCobra, Aug 1, 2009.

  1. #1
    Suppose my ftp info is:

    $ftp_server = "120.14.235.255";
    $ftp_user_name = "user123";
    $ftp_user_pass = "pass123";


    ** when i login by ftp client with this info, I see my file & folders after login (such as, myFolder1, myFolder2, myfile.php etc.)

    I want to create a xxx.txt file in myFolder1 dir and write something in that file same time.

    or,

    write somethig in a temp text file first and upload that file to myFolder1 dir.

    How can I do that?

    Please Help....
     
    KingCobra, Aug 1, 2009 IP
  2. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #2
    lowridertj, Aug 1, 2009 IP
  3. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Please help me solving this problem.

    I think to solve this you may use tmpfile(); function.
     
    KingCobra, Aug 2, 2009 IP
  4. Ntech

    Ntech Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If I understand your question you just want to create a file in one of your website's folders.

    There's no need to involve ftp for this.

    There's a really good beginners tutorial on working with files using php here: http://www.tizag.com/phpT/files.php
     
    Ntech, Aug 2, 2009 IP
  5. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #5
    <?php
    $fp = fopen('data.txt', 'w');
    fwrite($fp, '1');
    fwrite($fp, '23');
    fclose($fp);

    // the content of 'data.txt' is now 123 and not 23!
    ?>

    you need to create a .txt file on your ftp. fopen it and do what ever you need and fwrite it.
    follow this:http://us3.php.net/manual/en/function.fwrite.php

    hope it helps.
     
    astrazone, Aug 3, 2009 IP