PHPackages                             anomaly/file-field\_type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. anomaly/file-field\_type

ActiveStreams-addon[File &amp; Storage](/categories/file-storage)

anomaly/file-field\_type
========================

A file upload field type.

v2.3.0(5mo ago)054.1k↑400%222MITPHPCI failing

Since Aug 1Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/anomalylabs/file-field_type)[ Packagist](https://packagist.org/packages/anomaly/file-field_type)[ Docs](http://pyrocms.com/)[ RSS](/packages/anomaly-file-field-type/feed)WikiDiscussions 2.3 Synced 1mo ago

READMEChangelogDependencies (1)Versions (99)Used By (2)

File Field Type
===============

[](#file-field-type)

*anomaly.field\_type.file*

#### A file upload field type.

[](#a-file-upload-field-type)

The file field type provides a single file upload input with integration to the Files Module.

Features
--------

[](#features)

- Single file upload
- Integration with Files Module
- BelongsTo relationship with file records
- Folder restrictions for organized uploads
- File type/extension filtering
- Drag and drop upload support
- File browsing from media library
- Preview support for images and documents
- Configurable display modes

Configuration
-------------

[](#configuration)

### Basic Configuration

[](#basic-configuration)

```
protected $fields = [
    'attachment' => [
        'type' => 'anomaly.field_type.file'
    ]
];
```

### With Folder Restriction

[](#with-folder-restriction)

```
'document' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'folders' => ['documents']
    ]
]
```

### With File Type Restrictions

[](#with-file-type-restrictions)

```
'avatar' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'folders'    => ['avatars'],
        'extensions' => ['jpg', 'jpeg', 'png']
    ]
]
```

### With Display Mode

[](#with-display-mode)

```
'image' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'mode'    => 'compact',
        'folders' => ['images']
    ]
]
```

Usage Examples
--------------

[](#usage-examples)

### Basic File Upload

[](#basic-file-upload)

```
$stream->create([
    'attachment' => 1 // File ID
]);
```

### With File Upload in Form

[](#with-file-upload-in-form)

```
protected $fields = [
    'document' => [
        'type'  => 'anomaly.field_type.file',
        'rules' => [
            'required'
        ]
    ]
];
```

Accessing Values
----------------

[](#accessing-values)

### In Twig Templates

[](#in-twig-templates)

```
{# Display file name #}
{{ entry.attachment.name }}

{# Display file link #}
Download {{ entry.attachment.name }}

{# Display image #}
{% if entry.image %}

{% endif %}

{# Display image with manipulation #}

{# Check if file exists #}
{% if entry.document %}
    Document attached: {{ entry.document.name }}
{% endif %}

{# Get file properties #}
{{ entry.attachment.size }} bytes
{{ entry.attachment.extension }}
{{ entry.attachment.mime_type }}
```

### In PHP

[](#in-php)

```
$entry = $model->find(1);

// Get file object
$file = $entry->attachment;

if ($file) {
    // Get file properties
    $name = $file->name;
    $path = $file->path();
    $size = $file->size;
    $extension = $file->extension;
    $mimeType = $file->mime_type;

    // Get file ID
    $fileId = $entry->attachment_id;

    // Image manipulation
    if ($file->isImage()) {
        $thumbnail = $file->make()->fit(150, 150)->path();
    }
}
```

Setting Values
--------------

[](#setting-values)

### In Forms

[](#in-forms)

```
$form = $builder->make('example.module.test');
$form->on('saving', function(FormBuilder $builder) {
    $entry = $builder->getFormEntry();

    // Set file ID
    $entry->attachment = 5;
});
```

### Direct Assignment

[](#direct-assignment)

```
// Set by file ID
$entry->attachment_id = 10;
$entry->save();

// Or set by file object
$file = File::find(10);
$entry->attachment()->associate($file);
$entry->save();
```

Database Structure
------------------

[](#database-structure)

The file field type stores the file relationship as:

- **INTEGER** - Foreign key to `files_files.id`

Validation
----------

[](#validation)

### Required File

[](#required-file)

```
'attachment' => [
    'type'  => 'anomaly.field_type.file',
    'rules' => [
        'required'
    ]
]
```

### File Must Exist

[](#file-must-exist)

```
'document' => [
    'type'  => 'anomaly.field_type.file',
    'rules' => [
        'required',
        'exists:files_files,id'
    ]
]
```

Common Use Cases
----------------

[](#common-use-cases)

### User Avatar

[](#user-avatar)

```
'avatar' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'folders'    => ['avatars'],
        'extensions' => ['jpg', 'jpeg', 'png', 'gif'],
        'mode'       => 'compact'
    ]
]
```

### PDF Document Upload

[](#pdf-document-upload)

```
'contract' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'folders'    => ['contracts'],
        'extensions' => ['pdf']
    ],
    'rules' => [
        'required'
    ]
]
```

### Product Featured Image

[](#product-featured-image)

```
'featured_image' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'folders'    => ['products'],
        'extensions' => ['jpg', 'jpeg', 'png']
    ],
    'rules' => [
        'required'
    ]
]
```

### Report Attachment

[](#report-attachment)

```
'report' => [
    'type'   => 'anomaly.field_type.file',
    'config' => [
        'folders'    => ['reports'],
        'extensions' => ['pdf', 'doc', 'docx', 'xls', 'xlsx']
    ]
]
```

Best Practices
--------------

[](#best-practices)

1. **Restrict Folders**: Always limit uploads to specific folders for organization
2. **Validate Extensions**: Use extension restrictions for security
3. **Image Optimization**: Use image manipulation for thumbnails and responsive images
4. **Clean Up**: Implement cleanup for unused file records
5. **Check Existence**: Always check if file exists before accessing properties
6. **Use Relationships**: Leverage Eloquent relationships for easy access
7. **Consider Storage**: Monitor disk space for large file uploads

Requirements
------------

[](#requirements)

- Streams Platform ^1.10
- PyroCMS 3.10+
- Files Module

License
-------

[](#license)

The File Field Type is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

Authors
-------

[](#authors)

PyroCMS, Inc. - Ryan Thompson -

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity31

Limited adoption so far

Community29

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 65.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~390 days

Total

99

Last Release

163d ago

Major Versions

v1.1.22 → v2.0.02016-02-18

v2.2.32 → 3.0.x-dev2019-09-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/3dc718dba9317e897b74dcb30e5c06bd106e1ad72b2df5242b66bcc28053fbf3?d=identicon)[anomaly](/maintainers/anomaly)

---

Top Contributors

[![RyanThompson](https://avatars.githubusercontent.com/u/1099967?v=4)](https://github.com/RyanThompson "RyanThompson (68 commits)")[![edster](https://avatars.githubusercontent.com/u/656313?v=4)](https://github.com/edster "edster (7 commits)")[![bloveless](https://avatars.githubusercontent.com/u/535135?v=4)](https://github.com/bloveless "bloveless (6 commits)")[![mmodler](https://avatars.githubusercontent.com/u/1906217?v=4)](https://github.com/mmodler "mmodler (3 commits)")[![aidanwatt](https://avatars.githubusercontent.com/u/3669142?v=4)](https://github.com/aidanwatt "aidanwatt (2 commits)")[![samharrison7](https://avatars.githubusercontent.com/u/3359948?v=4)](https://github.com/samharrison7 "samharrison7 (2 commits)")[![weotch](https://avatars.githubusercontent.com/u/77567?v=4)](https://github.com/weotch "weotch (2 commits)")[![hup234design](https://avatars.githubusercontent.com/u/37693783?v=4)](https://github.com/hup234design "hup234design (1 commits)")[![itinnovative](https://avatars.githubusercontent.com/u/6822319?v=4)](https://github.com/itinnovative "itinnovative (1 commits)")[![jacksun101](https://avatars.githubusercontent.com/u/417021?v=4)](https://github.com/jacksun101 "jacksun101 (1 commits)")[![kiger](https://avatars.githubusercontent.com/u/2277562?v=4)](https://github.com/kiger "kiger (1 commits)")[![MarceauKa](https://avatars.githubusercontent.com/u/1665333?v=4)](https://github.com/MarceauKa "MarceauKa (1 commits)")[![aliselcuk](https://avatars.githubusercontent.com/u/966776?v=4)](https://github.com/aliselcuk "aliselcuk (1 commits)")[![oimken](https://avatars.githubusercontent.com/u/5130712?v=4)](https://github.com/oimken "oimken (1 commits)")[![Piterden](https://avatars.githubusercontent.com/u/5930429?v=4)](https://github.com/Piterden "Piterden (1 commits)")[![aldf](https://avatars.githubusercontent.com/u/11527940?v=4)](https://github.com/aldf "aldf (1 commits)")[![ujackson](https://avatars.githubusercontent.com/u/5864276?v=4)](https://github.com/ujackson "ujackson (1 commits)")[![schmidex](https://avatars.githubusercontent.com/u/2202857?v=4)](https://github.com/schmidex "schmidex (1 commits)")[![spektra2147](https://avatars.githubusercontent.com/u/39536659?v=4)](https://github.com/spektra2147 "spektra2147 (1 commits)")[![chareice](https://avatars.githubusercontent.com/u/1624785?v=4)](https://github.com/chareice "chareice (1 commits)")

---

Tags

streams addonfield typestreams field type

### Embed Badge

![Health badge](/badges/anomaly-file-field-type/health.svg)

```
[![Health](https://phpackages.com/badges/anomaly-file-field-type/health.svg)](https://phpackages.com/packages/anomaly-file-field-type)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
