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 
__construct(Pagefiles $pagefiles, string $filename)
(nothing)Construct a new Pagefile 
basename()
stringReturns the basename of this Pagefile (name and extension, without disk path).
Can also be used as property: basename
 
description()
string arrayGet or set the file’s description (with multi-language support).
Can also be used as property: description
 
ext()
stringReturns the file’s extension - "pdf", "jpg", etc.
Can also be used as property: ext
 
filemtime()
intGet last modified time of file 
filename()
stringReturns the full disk path name filename to the Pagefile.
Can also be used as property: filename
 
filesize()
intReturns the filesize in number of bytes.
Can also be used as property: filesize
 
filesizeStr()
stringReturns the filesize in a formatted, output-ready string (i.e. "123 kB")
Can also be used as property: filesizeStr
 
getFiles()
arrayGet all filenames associated with this file 
hash()
stringReturn a unique MD5 hash representing this Pagefile.
Can also be used as property: hash
 
hidden()
(nothing)Get or set hidden state of this file 
httpUrl()
stringReturn the web accessible URL (with scheme and hostname) to this Pagefile.
Can also be used as property: httpUrl
isNew()
boolGet or set “new” status of the Pagefile 
name string Returns the filename without the path, same as the "basename" property. 
noCacheURL()
string
save()
boolSave this Pagefile independently of the Page it lives on 
uploadName()
stringOriginal and unsanitized filename at the time it was uploaded
Can also be used as property: uploadName
 
url()
stringReturn the web accessible URL to this Pagefile.
Can also be used as property: url
 

Traversal

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

NameReturnSummary 
getNext()
Pagefile nullReturn the next sibling Pagefile in the parent Pagefiles, or NULL if at the end. 
getPrev()
Pagefile 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 
addTag($tag)
$thisAdd the given tag to this file’s tags (if not already present) 
description()
string arrayGet or set the file’s description (with multi-language support).
Can also be used as property: description
 
filedata()
mixedGet or set filedata
Can also be used as property: filedata
 
removeTag(string $tag)
$thisRemove the given tag from this file’s tags (if present) 
rename(string $basename)
string boolRename this file 
tags()
string arrayGet or set the "tags" property, when in use.
Can also be used as property: tags
 

Date time

NameReturnSummary 
created int Unix timestamp of when file was created.  
createdStr string Readable date/time string of when Pagefile was created  
modified int Unix timestamp of when Pagefile (file, description or tags) was last modified.  
modifiedStr string Readable date/time string of when Pagefile was last modified.  
mtime int Unix timestamp of when file (only) was last modified.  
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 
addTag($tag)
$thisAdd the given tag to this file’s tags (if not already present) 
hasTag(string $tag)
bool stringDoes this file have the given tag(s)? 
removeTag(string $tag)
$thisRemove the given tag from this file’s tags (if present) 
tags()
string arrayGet or set the "tags" property, when in use.
Can also be used as property: tags
 
tagsArray array Get file tags as an array.  

Other

NameReturnSummary 
HTTPURL string Same as the cache-busting uppercase “URL” property, but includes scheme and hostname.  
URL string Same as $url property but with browser cache busting query string appended.  
createdUser User NullPage User that added/uploaded the file or NullPage if not known (3.0.154)+.  
created_users_id int ID of user that added/uploaded the file or 0 if not known (3.0.154+).  
field Field The Field object that this file is part of.  
modifiedUser User NullPage User that last modified the file or NullPage if not known (3.0.154)+.  
modified_users_id int ID of user that last modified the file or 0 if not known (3.0.154+).  
page Page The Page object that this file is part of.  
pagefiles Pagefiles The Pagefiles WireArray that contains this file.  

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

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer