Results 1 to 5 of 5

Thread: Create new folder and .TXT file

  1. #1
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Create new folder and .TXT file

    Code:
    <?
    if($_POST['Submit']){
    $open = fopen("$username/$topurl.txt","w+");
    $text = $_POST['update'];
    fwrite($open, $text);
    fclose($open);
    echo "My notes:<br />";
    $file = file("$username/$topurl.txt");
    foreach($file as $text) {
    echo $text."<br />";
    }
    }else{
    $file = file("$username/$topfilename.txt");
    echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
    echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
    foreach($file as $text) {
    echo $text;
    } 
    echo "</textarea>";
    echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
    </form>";
    }
    ?>
    Hello, its me again. I have gotten a working login and registration system on my site and I would like to make it so that when a new user logs in and views a page, a new subdirectory is created named after the visitors username, if it does not already exist;

    Simeltaniously creating a new .TXT file named after the filename of whatever webpage they are on, if it does not already exist; if it does exist than the file contents are to be loaded into the TEXTAREA for further appending by the user.

    I know of the fcreate function, but I am not familiar with its paremeters or how to 'work it'

  2. #2
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Ok Ive worked a bit more and gotten thus far. The problem I keep encountering is that $username keeps coming empty instead of storing the logged-in visitors username, instead a new folder is created titled $username.
    And $username is supposed to hold a value because I use it to display a welcome message on the same page. And I've provided a+ as the paremeter, yet no file is being created. I just get error msg that file does not exist.
    Code:
    <?php
    mkdir('$username', 0777);
    if($_POST['Submit']){
    $url = $_SERVER['REQUEST_URI'];
    $open = fopen("$username/$url.txt","a+");
    $text = $_POST['update'];
    fwrite($open, $text);
    fclose($open);
    echo "My notes:<br />";
    $file = file("$username/$url.txt");
    foreach($file as $text) {
    echo $text;
    }
    }else{
    $url = $_SERVER['REQUEST_URI'];
    $file = file("$username/$url.txt");
    echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
    echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
    foreach($file as $text) {
    echo $text;
    } 
    echo "</textarea>";
    echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
    </form>";
    }
    ?>
    Best Regards
    ~Spine

  3. #3
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    You put the var in single quotes.
    This:
    Code:
    mkdir('$username', 0777);
    Should be:
    Code:
    mkdir("$username", 0777);
    or
    Code:
    mkdir($username, 0777);
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  4. #4
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Hi

    I am harish Pawar what i was looking out was, when i enter some data in the
    HTML form then that dynamic data should get saved in the .txt file with
    when i saw this it was some where near to this can u please help me on this


    Quote Originally Posted by Jas View Post
    You put the var in single quotes.
    This:
    Code:
    mkdir('$username', 0777);
    Should be:
    Code:
    mkdir("$username", 0777);
    or
    Code:
    mkdir($username, 0777);

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I think your searching for what I was a while ago and the answer can be found here: http://www.dynamicdrive.com/forums/s...xt+file&page=4

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •