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?       Only hookable?    

Common

NameReturnSummary 
Pagefile::__construct(Pagefiles $pagefiles, string $filename)
None

Construct a new Pagefile

 
Pagefile::basename()
string

Returns the basename of this Pagefile (name and extension, without disk path).


Can also be used as property: Pagefile::basename
 
Pagefile::description()
string array

Get or set the file’s description (with multi-language support).


Can also be used as property: Pagefile::description
 
Pagefile::ext()
string

Returns the file’s extension - "pdf", "jpg", etc.


Can also be used as property: Pagefile::ext
 
Pagefile::filemtime()
int

Get last modified time of file

 
Pagefile::filesize()
int

Returns the filesize in number of bytes.


Can also be used as property: Pagefile::filesize
 
Pagefile::filesizeStr()
string

Returns the filesize in a formatted, output-ready string (i.e. "123 kB")


Can also be used as property: Pagefile::filesizeStr
 
Pagefile::getFiles()
array

Get all filenames associated with this file

 
Pagefile::hash()
string

Return a unique MD5 hash representing this Pagefile.


Can also be used as property: Pagefile::hash
 
Pagefile::hidden()
None

Get or set hidden state of this file

 
Pagefile::httpUrl()
string

Return the web accessible URL (with scheme and hostname) to this Pagefile.


Can also be used as property: Pagefile::httpUrl
Pagefile::isNew()
bool

Get or set “new” status of the Pagefile

 
Pagefile::noCacheURL()
string
Pagefile::save()
bool

Save this Pagefile independently of the Page it lives on

 
Pagefile::uploadName()
string

Original and unsanitized filename at the time it was uploaded


Can also be used as property: Pagefile::uploadName
 

Traversal

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

NameReturnSummary 
Pagefile::getNext()
Pagefile null

Return the next sibling Pagefile in the parent Pagefiles, or NULL if at the end.

 
Pagefile::getPrev()
Pagefile null

Return 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)
$this

Add the given tag to this file’s tags (if not already present)

 
Pagefile::description()
string array

Get or set the file’s description (with multi-language support).


Can also be used as property: Pagefile::description
 
Pagefile::filedata()
mixed

Get or set filedata


Can also be used as property: Pagefile::filedata
 
Pagefile::removeTag(string $tag)
$this

Remove the given tag from this file’s tags (if present)

 
Pagefile::rename(string $basename)
string bool

Rename this file

 
Pagefile::tags()
string array

Get 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)
$this

Add the given tag to this file’s tags (if not already present)

 
Pagefile::hasTag(string $tag)
bool string

Does this file have the given tag(s)?

 
Pagefile::removeTag(string $tag)
$this

Remove the given tag from this file’s tags (if present)

 
Pagefile::tags()
string array

Get 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::createdUser User NullPage User that added/uploaded the file or NullPage if not known 3.0.154+.  
Pagefile::created_users_id int ID of user that added/uploaded the file or 0 if not known 3.0.154+.  
Pagefile::field Field The Field object that this file is part of.  
Pagefile::modifiedUser User NullPage User that last modified the file or NullPage if not known 3.0.154+.  
Pagefile::modified_users_id int ID of user that last modified the file or 0 if not known 3.0.154+.  
Pagefile::page Page The Page object that this file is part of.  
Pagefile::pagefiles Pagefiles The Pagefiles WireArray that contains this file.  

Properties

NameReturnSummary 
Pagefile::name string Returns the filename without the path, same as the "basename" property. 

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