SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creating txt files

    what function would i use to create a text file. and also how could make it so that everytime a new txt file is created it is called new01.txt, then if that exist new02.txt etc.

    thx
    hmm...

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depends what the txt files are for. If you just want to create them and put some text in, use:

    Code:
    fopen("TEXT-FILE", "aw");
    That would open 'TEXT-FILE' for writing and also puts the cursor at the top of the file, I think, which means newest entries at the top. It also creates the file if it doesn't exist.

    Maybe you could try a loop for creating the newxx.txt effect. Something that starts at 1 and increments using a file_exists() to see if it exists, then an else with the fopen code and a break.

    Or you could store a variable or number somewhere so the script cancreate the next file more quickly.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Look out! Multi-user!

    Hi,

    When creating files, make sure you either:
    - Create a temporary file
    - Fill it with data (this takes time)
    - Close the file (this takes time as well)
    - Rename the file to its final name (e.g. 'file-001.txt')
    Or:
    - Create the file (e.g. 'file-001.txt')
    - Lock the file
    - Fill it with data
    - Close the file- Unlock the file

    You should NEVER just open a file for writing and dump data in it. What if two users open your page at the same time? Believe me, this is trickier than you might think!

    Vincent


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
  •