Pagefiles class

Pagefiles is a type of WireArray that contains Pagefile objects. It also acts as the value for multi-file fields in ProcessWire.

The items in a Pagefiles array are Pagefile objects, indexed by file basename, i.e. myfile.pdf. Information on most traversal, filtering and manipulation methods can be found in the WireArray class that Pagefiles extends. In the examples below, $page->files is an instance of Pagefiles:

// Determining if any files are present
if($page->files->count()) {
  // There are files here
}

// Traversing and outputting links to all files
foreach($page->files as $name => $pagefile) {
  echo "<li><a href='$pagefile->url'>$name: $pagefile->description</a></li>";
}

// Adding new file(s)
$page->files->add('/path/to/file.pdf');
$page->files->add('http://domain.com/photo.png');
$page->save('files');

// Getting file by name
$pagefile = $page->files->getFile('file.pdf');
$pagefile = $page->files['file.pdf']; // alternate

// Getting first and last file
$pagefile = $page->files->first();
$pagefile = $page->files->last();

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Pagefiles class also inherits all the methods and properties of: WireArray and Wire.

Show class?             Show args?        

Common

NameReturnSummary 
Pagefiles::clone(Pagefile $item)
Pagefile boolDuplicate the Pagefile and add to this Pagefiles instance
Pagefiles::formatted()
boolGet or set formatted state 
Pagefiles::getField()
Field nullGet the field these files are assigned to 
Pagefiles::getFile(string $name)
null PagefileGet the Pagefile having the given basename, or null if not found. 
Pagefiles::getPage()
PageGet the page these files are assigned to 
Pagefiles::path()
stringReturn the full disk path where files are stored
Can also be used as property: Pagefiles::path
 
Pagefiles::setField(Field $field)
(nothing)Set the field these files are assigned to 
Pagefiles::setPage(Page $page)
(nothing)Set the Page these files are assigned to 
Pagefiles::url()
stringReturns the web accessible index URL where files are stored
Can also be used as property: Pagefiles::url
 

Manipulation

NameReturnSummary 
Pagefiles::add($item)
$thisAdd a new Pagefile item or filename 
Pagefiles::delete($item)
$thisDelete a pagefile item
Pagefiles::deleteAll()
$thisDelete all files associated with this Pagefiles instance, leaving a blank Pagefiles instance. 
Pagefiles::rename(Pagefile $item, string $name)
PagefilesQueue a rename of a Pagefile 

Tags

NameReturnSummary 
Pagefiles::findTag($tag)
PagefilesReturn all Pagefile objects that have the given tag(s). 
Pagefiles::getTag(string $tag)
Pagefile nullReturn the first Pagefile that matches the given tag or NULL if no match 
Pagefiles::tags()
string array PagefilesGet list of tags for all files in this Pagefiles array, or return files matching given tag(s) 

Other

NameReturnSummary 
Pagefiles::field Field Returns the Field that contains this set of files, same as the getField() method.  
Pagefiles::page Page Returns the Page that contains this set of files, same as the getPage() method.  

Additional methods and properties

In addition to the methods and properties above, Pagefiles also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.124

Twitter updates

  • New post: In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124— More
    11 January 2019
  • New ProcessWire main site rebuild ready for preview— More
    4 January 2019
  • Happy Holidays! This latest master version of ProcessWire contains hundreds of new additions, fixes, optimizations and more. This post covers all the highlights— More
    21 December 2018

Latest news

  • ProcessWire Weekly #245
    In the 245th issue of ProcessWire Weekly we're going to focus on some new documentation additions made just this week, cover a couple of new third party modules from Bernhard Baumrock, and introduce a magnificent new travel website called Uncover Colombia. Read on!
    Weekly.pw / 19 January 2019
  • ProcessWire 3.0.124 and new website launched
    In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124.
    Blog / 11 January 2019
  • 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