PagefilesManager class

Manages files and file directories for a page independent of a particular field.

Files in ProcessWire are always connected with a particular Field on a Page. This is typically a FieldtypeFile field or a FieldtypeImage field, which exist as Pagefiles or Pageimages values on the Page. Sometimes it is necessary to manage all files connected with a page as a group, and this files manager class provides that. Likewise, something needs to manage the paths and URLs where these files live, and that is where this files manager comes into play as well.

Summary of what PagefilesManager does

  • Provides methods for movement of all files connected with a page as a group.
  • Ensures that file directories for a page are created (and removed) when applicable.
  • Manages secured vs. normal page file paths (see $config->pagefileSecure).
  • Manages extended vs. normal page file paths (see $config->pagefileExtendedPaths).

How to access the Page files manager

The Page files manager can be accessed from any page’s Page::filesManager() method or property.

// Example of getting a Page’s dedicated file path and URL
$filesPath = $page->filesManager->path();
$filesURL = $page->filesManager->url();

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

Show class?             Show args?        

Common

NameReturnSummary 
PagefilesManager::getFile(string $name)
Pagefile Pageimage nullGet the Pagefile object containing the given filename. 
PagefilesManager::getFiles()
arrayGet an array of all published filenames on the current Page. 
PagefilesManager::getTempPath()
stringReturn a path where temporary files can be stored unique to this ProcessWire instance 
PagefilesManager::page Page Page that this files manager is for.  
PagefilesManager::path()
stringGet the published path for files
Can also be used as property: PagefilesManager::path
 
PagefilesManager::url()
stringGet the published URL for files
Can also be used as property: PagefilesManager::url
 

For hooks

These methods are only useful for hooking and should not be called directly.

NameReturnSummary 
PagefilesManager::save()
(nothing)For hooks to listen to on page save action, for file-specific operations

Static

These methods are not connected with a particular instance and may only be called statically.

NameReturnSummary 
PagefilesManager::dirToPageID(string $dir)
intGiven a dir (URL or path) to a files directory, return the page ID associated with it. 
PagefilesManager::hasFiles(Page $page)
boolReturns true if Page has a path and files, false if not. 
PagefilesManager::hasPath(Page $page)
boolReturns true if Page has a files path that exists. 

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core. More
    8 November 2019
  • ProcessWire 3.0.144 core updates: Upgraded overrides section in the field editor, a new Inputfields JS API, and more— More
    1 November 2019
  • ProcessWire 3.0.143 core updates — 26 commits and 18 resolved issue reports, plus some other useful improvements and additions. More here: More
    25 October 2019

Latest news

  • ProcessWire Weekly #288
    In the 288th issue of ProcessWire Weekly we'll cover the latest core updates, introduce WireMailSendGrid, host a new weekly poll, and showcase a new site of the week. Read on!
    Weekly.pw / 16 November 2019
  • ProcessWire 3.0.145 core updates
    ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core.
    Blog / 8 November 2019
  • 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