$files->unlink() method

Unlink/delete file with additional protections relative to PHP unlink()

  • This method requires a full pathname to a file to unlink and does not accept any kind of relative path traversal.

  • This method will only unlink files in /site/assets/ if you specify true for the $limitPath option (recommended).

Available since version 3.0.118.


// basic usage
$bool = $files->unlink(string $filename);

// usage with all arguments
$bool = $files->unlink(string $filename, $limitPath = false, bool $throw = false);


limitPath (optional)string, bool

Limit only to files within some starting path? (default=false)

  • Boolean true to limit unlink operations to somewhere within /site/assets/ (only known always writable path).
  • Boolean false to disable to security feature. (default)
  • An alternative path (string) that represents the starting path (full disk path) to limit deletions to.
  • An array with multiple of the above string option.
throw (optional)bool

Throw exception on error?

Return value


True on success, false on fail


Method can throw exceptions on error:

  • WireException - If file is not allowed to be removed or unlink fails

$files methods and properties

API reference based on ProcessWire core version 3.0.160

Twitter updates

  • 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
  • Preview of ProcessWire 3.0.160 with auto-enable of two-factor authentication, new version of TfaEmail and TfaTotp, and new selector operators coming next week. More
    12 June 2020

Latest news

  • ProcessWire Weekly #319
    In the 319th issue of ProcessWire Weekly we're going to check out the latest core updates, introduce a couple of new third party modules, and highlight the downright stunning new website of Studio Pixelgold. Read on!
    Weekly.pw / 21 June 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

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani