$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 be limited to unlink files only 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.185

Twitter updates

  • Great video by @jlahijani that demonstrates his ProcessWire page builder using ProFields Repeater Matrix, the new Page Autosave + Live Preview module and Uikit 3— youtube.com/watch?v=Rb5kiU…
    13 November 2021
  • More development on page automatic save this week, plus the addition of live preview— More
    12 November 2021
  • ProcessWire 3.0.189 core updates— More
    5 November 2021

Latest news

  • ProcessWire Weekly #394
    In the 394th issue of ProcessWire Weekly we'll share the latest ProcessWire news and updates, including some highlights from the support forum, the latest weekly update from Ryan, and more. Read on!
    Weekly.pw / 27 November 2021
  • New Repeater and Repeater Matrix features
    This week we have some very useful new additions to both the core Repeater Fieldtype and the ProFields Repeater Matrix Fieldtype. This post covers all the details along with a couple of brief demonstration videos. 
    Blog / 22 October 2021
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer