#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    65
    Rep Power
    15
    Is there a way for PHP to create a file, write content to it, and then close the file? Or do I need a blank document already there for to write to and then rename to something else?
    TIA,
    Ben
  2. #2
  3. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Yes, there are all sorts of ways PHP can read a file and it will create it if you try and write to it and the file doesn't exist. Go to the PHP manual at http://www.php.net and have a read.

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Indonesia
    Posts
    87
    Rep Power
    15
    You can use fopen function.
    Set the mode into "w".
    If the file doesn't exist, it will create it for you.

    HANDLE = fopen("filename","w");



    ------------------
    ** It's the world of Oscario **
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    14
    Yes Use fopen with a filE handler to open the file use fputs or fwrite() function to write into the file and fclose() function to close the file . As simple as that
  8. #5
  9. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    61
    Yes, but you also need to remember your permissions; the directory where you want PHP to write a file must be either world-readable/worldwriteable (bad) or chowned to nobody:nobody (good).

Similar Threads

  1. Blank lines when writing to a file
    By RobinR in forum ASP Programming
    Replies: 3
    Last Post: February 13th, 2004, 03:00 PM
  2. writing a file to a ftp server
    By buddinghere in forum FTP Help
    Replies: 1
    Last Post: February 12th, 2004, 10:36 AM
  3. Pointer problem in opening a file
    By LAKI in forum C Programming
    Replies: 13
    Last Post: February 11th, 2004, 08:27 AM
  4. Pointer problems opening file *formatted*
    By LAKI in forum C Programming
    Replies: 4
    Last Post: February 11th, 2004, 06:06 AM
  5. Writing a Tree to a file
    By booyeah! in forum C Programming
    Replies: 0
    Last Post: February 5th, 2004, 05:40 PM

IMN logo majestic logo threadwatch logo seochat tools logo