FieldtypeFile

Field that stores one or more uploaded files with optional descriptions and tags.

Value type

The value type depends on the field's outputFormat setting (when output formatting is on):

  • outputFormat=auto (default) — Pagefiles when maxFiles allows multiple; Pagefile|null when maxFiles=1
  • outputFormat=array — always Pagefiles
  • outputFormat=singlePagefile|null
  • outputFormat=string — rendered string using the outputString template

When output formatting is off: always a Pagefiles object.

Getting and setting values

All "setting" values or other manipulations should take place only when $page output formatting is OFF.

// Iterate files (Pagefiles, multi-file)
foreach($page->files_field as $file) {
    echo "<li><a href='$file->url'>$file->name</a> ($file->filesizeStr)</li>";
}

// Get single file (when outputFormat=single or auto with maxFiles=1)
$file = $page->files_field;
if($file) echo "<a href='$file->url'>$file->description</a>";

// Get a specific file by name
$file = $page->files_field->get('document.pdf');

// Add a file from a local path or URL
$page->files_field->add('/path/to/file.pdf');
$page->save('files_field');

// Remove a file (actual delete occurs on save)
$pagefile = $page->files_field->get('document.pdf');
if($pagefile) {
    $page->files_field->delete($pagefile);
    $page->save('files_field');
}

// Remove all files (actual delete occurs on save)
$page->files_field->deleteAll();

// Rename file (actual rename occurs on save)
$pagefile = $page->files_field->get('document.pdf');
if($pagefile) {
    $page->files_field->rename($pagefile, 'hello.pdf');
    $page->save('files_field');
}

// Duplicate a file
$pagefile = $page->files_field->get('document.pdf');
if($pagefile) {
    $copy = $page->files_field->clone($pagefile);
    $copy->description = 'Copy of document.pdf'; // optional
    $page->save('files_field');
}
Pagefile properties

Each item in a Pagefiles collection is a Pagefile object:

$file->url          // URL to the file
$file->httpUrl      // Full URL including http(s)://
$file->filename     // Filesystem path to the file
$file->name         // Basename (e.g. 'document.pdf')
$file->ext          // Extension without dot (e.g. 'pdf')
$file->description  // Description text (output-formatted when OF is on)
$file->tags         // Space-separated tags string (when tags are enabled)
$file->filesize     // File size in bytes
$file->filesizeStr  // Human-readable size (e.g. '1.2 MB')
$file->created      // Unix timestamp of when file was added
$file->modified     // Unix timestamp of last modification
$file->page         // Page this file belongs to
Pagefiles methods
$files->count()              // Number of files
$files->first()              // First Pagefile, or false if empty
$files->last()               // Last Pagefile, or false if empty
$files->get('file.pdf')      // Get Pagefile by name, or null if not found
$files->findTag('sidebar')   // Returns new Pagefiles containing all items with tag
$files->getTag('hero')       // Returns first Pagefile with that tag, or null
$files->add('/path/to/file') // Add a file from a local path or URL
$files->delete($f)           // Mark Pagefile ($f) for deletion (call $page->save() after)
$files->deleteAll()          // Mark all files for deletion (call $page->save() after)
$files->rename($f, 'x.pdf')  // Rename Pagefile ($f) to x.pdf (call $page->save() after)
$copy = $files->clone($f)    // Duplicate Pagefile ($f) and return Pagefile copy (call $page->save() after)

Note: Above are examples but Pagefiles also inherits all WireArray methods. Please use delete() and deleteAll() rather than WireArray remove() and removeAll().

Selectors
// Pages that have at least one file
$pages->find('files_field.count>0');

// Pages with a specific filename
$pages->find('files_field=brochure.pdf');

// Pages whose file description contains a word (fulltext)
$pages->find('files_field.description%=annual');

// Pages with files larger than 1 MB
$pages->find('files_field.filesize>1048576');

// Pages with files created after a date
$pages->find('files_field.created>2025-01-01');

// Pages with files tagged 'sidebar' (requires tags enabled on field)
$pages->find('files_field.tags*=sidebar');

// Pages with a custom subfield value (requires custom fields enabled on field)
$pages->find('files_field.custom_subfield=value');

Usable subfields: data (filename), description, count, filesize, created, modified, created_users_id, modified_users_id, tags (when enabled), plus any custom field names.

Output / markup
// Render a list of download links (multi-files field)
$out = '';
foreach($page->files_field as $file) {
    $out .= "<li><a href='$file->url'>$file->description</a> ($file->filesizeStr)</li>";
}
if($out) echo "<ul>$out</ul>";

// Get a file by tag and link it
$pdf = $page->files_field->getTag('brochure');
if($pdf) echo "<a href='$pdf->url'>Download brochure</a>";

// Display only files matching a specific tag
foreach($page->files_field->findTag('sidebar') as $file) {
    echo "<a href='$file->url'>$file->name</a><br>";
}
Notes
  • Files are stored at /site/assets/files/{page_id}/ on the filesystem.
  • outputFormat=auto (default) returns Pagefiles unless maxFiles=1, in which case it returns Pagefile|null.
  • outputFormat=string renders each file using the outputString template (supports {url}, {description}, {tags} placeholders). When there are multiple files, the string is rendered once per file and concatenated.
  • The defaultValuePage setting causes an empty field to fall back to files from another specified page.
  • Custom per-file metadata (beyond description and tags) is enabled via the "Custom fields" feature, which creates a template named field-{fieldname}.
  • Tags require the useTags setting to be enabled; predefined tags are configured via tagsList.
  • Text formatters (e.g., TextformatterEntities) are applied to file descriptions when output formatting is on.
API reference: methods, properties, hooks

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

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
FieldtypeFile::cloneField(Field $field)
Field

Return a cloned copy of $field

FieldtypeFile::deleteField(Field $field)
bool

Delete field

FieldtypeFile::deletePageField(Page $page, Field $field)
bool

Delete field from page

FieldtypeFile::emptyPageField(Page $page, Field $field)
bool

Empty field from page

FieldtypeFile::exportValue(Page $page, Field $field, $value)
array float int string

Export value

FieldtypeFile::formatValue(Page $page, Field $field, Pagefiles $value)
Pagefiles Pagefile

Perform output formatting on the value delivered to the API

FieldtypeFile::get($key)
None 
FieldtypeFile::getBlankValue(Page $page, Field $field)
Pagefiles

Get blank value

 
FieldtypeFile::getCompatibleFieldtypes(Field $field)
Fieldtypes

Get compatible Fieldtypes

FieldtypeFile::getConfigAdvancedInputfields(Field $field)
InputfieldWrapper

Field advanced config

FieldtypeFile::getConfigInputfields(Field $field)
InputfieldWrapper

Field config

FieldtypeFile::getDatabaseSchema(Field $field)
array

Get database schema

 
FieldtypeFile::getFieldClass()
string

Get the Field class to use for fields of this type

 
FieldtypeFile::getFieldSetups()
array

Get setup options and setup functions for new fields

FieldtypeFile::getFilesPath(Page $page, Field $field)
string

Get path where files are (or would be) stored

 
FieldtypeFile::getInputfield(Page $page, Field $field)
Inputfield

Get the Inputfield module to handle input for this Fieldtype

 
FieldtypeFile::getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query)
DatabaseQuerySelect null

Disable autojoin for files

 
FieldtypeFile::getMatchQuery($query, string $table, string $subfield, string $operator, mixed $value)
DatabaseQuery DatabaseQuerySelect

Get match query

 
FieldtypeFile::getPagefile(Page $page, string $basename)
Pagefile null

Given a Page and file basename, return the Pagefile object if file is found for Page

 
FieldtypeFile::getPagefiles(Page $page, Field $field)
Pagefiles

Get Pagefiles

 
FieldtypeFile::getSelectorInfo(Field $field)
array

Get selector info

FieldtypeFile::getValidFileExtensions($field)
array

Check file extensions for given field and return array of validity information

 
FieldtypeFile::importValue(Page $page, Field $field, $value)
array float int string

Import value

FieldtypeFile::loadPageField(Page $page, Field $field)
array null

@param Page $page

FieldtypeFile::markupValue(Page $page, Field $field)
string MarkupFieldtype

Render a markup string of the value.

FieldtypeFile::renamedField(Field $field, string $prevName)
None

Called after field renamed

FieldtypeFile::sanitizeValue(Page $page, Field $field, mixed $value)
Pagefiles

Sanitize value

 
FieldtypeFile::sleepValue(Page $page, Field $field, $value)
array

Given an 'awake' value, as set by wakeupValue, convert the value back to a basic type for storage in DB.

FieldtypeFile::wakeupValue(Page $page, Field $field, $value)
Pagefiles null

Given a raw value (value as stored in DB), return the value as it would appear in a Page object

Properties

NameReturnSummary 
FieldtypeFile::allowFieldtypes array Allowed Fieldtype types for custom fields 
FieldtypeFile::defaultFileExtensions string Default file extensions
DEFAULT: pdf doc docx xls xlsx gif jpg jpeg png
 

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.259