$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 #543
    In the 543rd issue of ProcessWire Weekly we'll check out the latest weekly update from Ryan, introduce a couple of new third party modules — both authored by Bernhard Baumrock — and more. Read on!
    Weekly.pw / 5 October 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH