note 62641 deleted from function.file-put-contents by sobak
| From: | sobak@php.net | Date: | Fri, 02 Dec 2016 03:56:59 +0000 |
| Subject: | note 62641 deleted from function.file-put-contents by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207925@lists.php.net to get a copy of this message | ||
Note Submitter: sendoshin at awswan dot com
----
To clear up what was said by pvenegas+php at gmail dot com on 11-Oct-2005 08:13, file_put_contents()
will replace the file by default. Here's the complete set of rules this function follows when
accessing a file:
1. Was FILE_USE_INCUDE_PATH passed in the call? If so, check the include path for an existing copy
of *filename*.
2. Does the file already exist? If not, first create it in the current working directory. Either
way, open the file.
3. Was LOCK_EX passed in the call? If so, lock the file.
4. Was the function called with FILE_APPEND? If not, clear the file's contents. Otherwise,
move to the end of the file.
5. Write *data* into the file.
6. Close the file and release any locks.
If you don't want to completely replace the contents of the file you're writing to, be
sure to use FILE_APPEND (same as fopen() with 'a') in the *flags*. If you don't,
whatever used to be there will be gone (fopen() with 'w').
Hope that helps someone (and that it makes sense ^^)!
- Sendoshin