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

Usage

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

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

Arguments

NameType(s)Description
filenamestring
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

bool

True on success, false on fail

Exceptions

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.236

Latest news

  • ProcessWire Weekly #515
    In the 515th issue of ProcessWire Weekly we’ll check out the latest core updates, new modules, and more. Read on!
    Weekly.pw / 23 March 2024
  • Invoices Site Profile
    The new invoices site profile is a free invoicing application developed in ProcessWire. It enables you to create invoices, record payments to them, email invoices to clients, print invoices, and more. This post covers all the details.
    Blog / 15 March 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits