Introduction

The upload field type provides a simple file input.

Configuration

Below is the full configuration available with defaults values:

"example" => [
    "type"   => "anomaly.field_type.upload",
    "config" => [
        "folder" => null,
        "image"  => false,
        "mimes"  => [],
        "max"    => null,
    ]
]
Configuration
Key Example Description

folder

"images"

The slug or ID of the upload folders.

image

true

Whether to only allow image uploads or not.

mimes

["jpg", "jpeg", "png"]

The allowed file types to upload.

max

2

The max upload size in megabytes. Defaults to folder max which may default to system max if not specified.

Installation

You can install the Upload field type with Composer using our packages.pyrocms.com repository included in your installation:

{
     "require": {
        "anomaly/upload-field_type": "~1.0.0"
    }
}

Or simply require it with composer:

composer require anomaly/upload-field_type

Usage

This section will show you how to use the field type via API and in the view layer.

Basic Output

The upload field type always returns null or an \Anomaly\FilesModule\File\Contract\FileInterface instance.

Example
$entry->example->getName(); // example.jpg
$entry->example->route('download'); // The download url
Twig
{{ entry.example.getName() }} // example.jpg
{{ entry.example.route('download') }} // The download url

Setting Values

You can set the upload field type value with a file's ID.

$entry->example = 10;

You can also set the value with an instance of a file.

$entry->example = $file;

Lastly you can set the value with an instance of a file presenter.

$entry->example = $decorated;

Presenter Output

When accessing the field value from a decorated entry model the an instance of \Anomaly\FilesModule\File\FilePresenter will be returned.

Example
$decorated->example->path; // local://folder/file.ext

$decorated->example->url() }} // /app/{application}/example/image.jpg
Twig
{{ decorated.example.path }} // local://folder/file.ext

{{ decorated.example.url }} // /app/{application}/example/image.jpg