Pagefile class

Represents a single file item attached to a page, typically via a File Fieldtype.

Pagefile objects are contained by a Pagefiles object.


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

Show class?             Show args?        

Common

NameReturnSummary 
Pagefile::__construct(Pagefiles $pagefiles, string $filename)
(nothing)Construct a new Pagefile 
Pagefile::basename()
stringReturns the basename of this Pagefile (name and extension, without disk path).
Can also be used as property: Pagefile::basename
 
Pagefile::description()
string arrayGet or set the file’s description (with multi-language support).
Can also be used as property: Pagefile::description
 
Pagefile::ext()
stringReturns the file’s extension - "pdf", "jpg", etc.
Can also be used as property: Pagefile::ext
 
Pagefile::filedata array 
Pagefile::filename()
stringReturns the full disk path name filename to the Pagefile.
Can also be used as property: Pagefile::filename
 
Pagefile::filesize()
intReturns the filesize in number of bytes.
Can also be used as property: Pagefile::filesize
 
Pagefile::filesizeStr()
stringReturns the filesize in a formatted, output-ready string (i.e. "123 kB")
Can also be used as property: Pagefile::filesizeStr
 
Pagefile::hash()
stringReturn a unique MD5 hash representing this Pagefile.
Can also be used as property: Pagefile::hash
 
Pagefile::httpUrl()
stringReturn the web accessible URL (with scheme and hostname) to this Pagefile.
Can also be used as property: Pagefile::httpUrl
Pagefile::name string Returns the filename without the path, same as the "basename" property. 
Pagefile::noCacheURL()
string
Pagefile::url()
stringReturn the web accessible URL to this Pagefile.
Can also be used as property: Pagefile::url
 

Traversal

For the most part you’ll want to traverse from the parent Pagefiles object than these methods.

NameReturnSummary 
Pagefile::getNext()
Pagefile Wire nullReturn the next sibling Pagefile in the parent Pagefiles, or NULL if at the end. 
Pagefile::getPrev()
Pagefile Wire nullReturn the previous sibling Pagefile in the parent Pagefiles, or NULL if at the beginning. 

Manipulation

Remember to follow up any manipulations with a $pages->save() call.

NameReturnSummary 
Pagefile::addTag($tag)
$thisAdd the given tag to this file’s tags (if not already present) 
Pagefile::description()
string arrayGet or set the file’s description (with multi-language support).
Can also be used as property: Pagefile::description
 
Pagefile::removeTag(string $tag)
$thisRemove the given tag from this file’s tags (if present) 
Pagefile::rename(string $basename)
string boolRename this file 
Pagefile::tags()
string arrayGet or set the "tags" property, when in use.
Can also be used as property: Pagefile::tags
 

Date time

NameReturnSummary 
Pagefile::created int Unix timestamp of when file was created.  
Pagefile::createdStr string Readable date/time string of when Pagefile was created  
Pagefile::modified int Unix timestamp of when Pagefile (file, description or tags) was last modified.  
Pagefile::modifiedStr string Readable date/time string of when Pagefile was last modified.  
Pagefile::mtime int Unix timestamp of when file (only) was last modified.  
Pagefile::mtimeStr string Readable date/time string when file (only) was last modified.  

For hooks

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

Tags

Be sure to see the Pagefiles::getTag() and Pagesfiles::findTag() methods, which enable you retrieve files by tag.

NameReturnSummary 
Pagefile::addTag($tag)
$thisAdd the given tag to this file’s tags (if not already present) 
Pagefile::hasTag(string $tag)
bool stringDoes this file have the given tag(s)? 
Pagefile::removeTag(string $tag)
$thisRemove the given tag from this file’s tags (if present) 
Pagefile::tags()
string arrayGet or set the "tags" property, when in use.
Can also be used as property: Pagefile::tags
 
Pagefile::tagsArray array Get file tags as an array.  

Other

NameReturnSummary 
Pagefile::HTTPURL string Same as the cache-busting uppercase “URL” property, but includes scheme and hostname.  
Pagefile::URL string Same as $url property but with browser cache busting query string appended.  
Pagefile::field Field The Field object that this file is part of.  
Pagefile::page Page The Page object that this file is part of.  
Pagefile::pagefiles Pagefiles The Pagefiles WireArray that contains this file.  
Pagefile::sort int Sort order in database.  

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #283
    The 283rd issue of ProcessWire Weekly introduces ProcessWire 3.0.142 and FormBuilder v40, highlights some conference content, and features a new weekly poll continuing with the #processwireworks theme. Read on!
    Weekly.pw / 12 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, bnd the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • 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