$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.234

Latest news

  • ProcessWire Weekly #511
    In the 511th issue of ProcessWire Weekly we'll cover the latest core updates, introduce a new third party module called Auto AVIF, and more. Read on!
    Weekly.pw / 25 February 2024
  • 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

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer