file_put_contents
(PHP 5)
file_put_contents — Write a string to a file
Description
int file_put_contents (
string $filename ,
mixed $data [,
int $flags [,
resource $context ]] )
If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flags is set.
Parameters
- 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 (explained above).
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($filename, implode('', $array)).
- flags
-
The value of flags can be any combination of the following flags (with some restrictions), joined with the binary OR (|) operator.
- context
-
A valid context resource created with stream_context_create().
Return Values
The function returns the number of bytes that were written to the file, or FALSE on failure.
Notes
Note: This function is binary-safe.