$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)

$files methods and properties

API reference based on ProcessWire core version 3.0.161

Twitter updates

  • New ProcessWire query expansion search operators can now add automatic word inflections and lemmatisation, enabling you to build even smarter search engines with ProcessWire. More
    3 July 2020
  • ProcessWire 3.0.161 adds support for selector operator stacking, enabling you automatically broaden searches in a single pages.find() call— More
    26 June 2020
  • ProcessWire 3.0.160 adds powerful new text-searching operators, bringing a new level of power to page-finding API calls, especially when it comes to search engine type queries. Post also includes a demo search engine where you can test it all out live— More
    19 June 2020

Latest news

  • ProcessWire Weekly #321
    In the 321st issue of ProcessWire Weekly we're going to check out the latest core updates, introduce two new third party modules, and check out a brand new site of the week. Read on!
    Weekly.pw / 4 July 2020
  • Powerful new text-searching abilities in 3.0.160
    In ProcessWire 3.0.160 we’ve got some major upgrades and additions to our text-search abilities. This brings a whole new level of power to $pages->find() and similar API calls, especially when it comes to search engine type queries.
    Blog / 19 June 2020
  • 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