SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    create a new text file?

    Hey,

    I'm trying to write a script that looks for my log file. If the file isn't there, it should create a new one. I can't seem to find a php filesystem function to do this? Is there one? This is where I'm at:

    Code:
    $sLog = "log.txt";
      if(!file_exists($sLog)) {
        //create the file
      }

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can touch() a file. If you want to write to the file as well as create it, use fopen() with the "w" mode.

  3. #3
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $sLog = "log.txt";
    if(!file_exists($sLog)) {
        touch($sLog);
    }
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you.

  5. #5
    SitePoint Enthusiast emplynx's Avatar
    Join Date
    Apr 2003
    Location
    West Virginia
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by redemption
    You can touch() a file. If you want to write to the file as well as create it, use fopen() with the "w" mode.
    Will fopen() create a file that doesn't exist?

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, as Joel said

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by emplynx
    Will fopen() create a file that doesn't exist?
    Yes, if you open a file with 'w', and it does not exist, and PHP has permission to do so, it will create a new file.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •