file_put_contents()
file_put_contents - Write a string to a file
Syntax
int file_put_contents (
string $filename,
mixed $data,
int $flags,
resource $context)
Arguments
- filename - Path to the file where to write the data.
- data - The data to write. Can be either a string, an array or a stream resource. If data is a stream resource, the remaining buffer of that stream will be copied to the specified file. This is similar with using stream_copy_to_stream(). You can also specify the data parameter as a single dimension array. This is equivalent to file_put_contents(, implode(\'\', )).
- flags - The value of flags can be any combination of the following flags (with some restrictions), joined with the binary OR ( |) operator. Available flags Flag Description FILE_USE_INCLUDE_PATH Search for filename in the include directory. See include_pathfor more information. FILE_APPEND If file filename already exists, append the data to the file instead of overwriting it. Mutually exclusive with LOCK_EX since appends are atomic and thus there is no reason to lock. LOCK_EX Acquire an exclusive lock on the file while proceeding to the writing. Mutually exclusive with FILE_APPEND.
- context - A valid context resource created with stream_context_create().
Description
This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file.
Version
PHP 5
Return value
The function returns the number of bytes that were written to the file, or FALSE on failure.