Writing the Contents of a File

Problem

You want to create or replace a file's contents.

Solution

Use the File::put() method.

$bytes_written = File::put($file, $contents);
if ($bytes_written === false)
{
    die("Error writing to file");
}

Discussion

This is a wrapper over PHP's file_put_contents().

comments powered by Disqus