$files->filePutContents() method

Create (overwrite or append) a file, put the $contents in it, and adjust permissions

This is the same as PHP’s file_put_contents() except that it’s preferable to use this in ProcessWire because it adjusts the file permissions configured with $config->chmodFile.


// basic usage
$int = $files->filePutContents(string $filename, $contents);

// usage with all arguments
$int = $files->filePutContents(string $filename, $contents, int $flags = 0);



Filename to write to

contentsstring, mixed

Contents to write to file

flags (optional)int

Flags to modify behavior:

  • FILE_APPEND (constant): Append to file if it already exists.
  • LOCK_EX (constant): Acquire exclusive lock to file while writing.

Return value

int bool

Number of bytes written or boolean false on fail


Method can throw exceptions on error:

  • WireException - if given invalid $filename (since 3.0.118)

See Also

$files methods and properties

API reference based on ProcessWire core version 3.0.228

Latest news

  • ProcessWire Weekly #498
    The 498th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 25 November 2023
  • Using date range fields in ProcessWire
    This week we'll take a detailed look at the newest addition to the ProFields set of modules: the Date Range Fieldtype and Inputfield.
    Blog / 24 November 2023
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer