SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,209
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    creating a new file

    I have a file named "createFile.php" for creating a new file in the same directory in which the file "createFile.php" is.

    What code should I put in "createFile.php" for creating a new file named "newFile.php"?

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'newFile.php', 'contents-of-the-file');

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,209
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Avram View Post
    Code:
    file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'newFile.php', 'contents-of-the-file');
    Your code works fine.
    Thank you, Avram.

    By the way,
    if the directory which has the file createFile.php has a sub-directory named "my_subDirectory",
    How can I put a "newFile.php" into "my_subDirectory"?

    The trial code below doesn't work correctly, but I hope it shows what I want.
    Code:
    file_put_contents(dirname(__my_subDirectory__) . '/' . 'newFile.php', 'contents-of-the-file_in_my_subDirectory');

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Code:
    file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'my_subDirectory/newFile.php', 'contents-of-the-file');

  5. #5
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,209
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Avram View Post
    Try this:

    Code:
    file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'my_subDirectory/newFile.php', 'contents-of-the-file');
    Thank you again, Avram.

    I have another question related on this.

    I like to create a new directory instead of a new file.
    How can I create a new directory named "newDirectory" in the directory which has the file "createDirectory.php"?

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    mkdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'newDirectory');


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
  •