PHPackages                             tatter/files - 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. tatter/files

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

tatter/files
============

File uploads and management, for CodeIgniter 4

v2.3.2(4y ago)643.0k17[7 issues](https://github.com/tattersoftware/codeigniter4-files/issues)[1 PRs](https://github.com/tattersoftware/codeigniter4-files/pulls)MITPHPPHP ^7.3 || ^8.0

Since Aug 12Pushed 2y ago10 watchersCompare

[ Source](https://github.com/tattersoftware/codeigniter4-files)[ Packagist](https://packagist.org/packages/tatter/files)[ Docs](https://github.com/tattersoftware/codeigniter4-files)[ Fund](https://paypal.me/tatter)[ GitHub Sponsors](https://github.com/tattersoftware)[ RSS](/packages/tatter-files/feed)WikiDiscussions develop Synced 2w ago

READMEChangelog (10)Dependencies (16)Versions (19)Used By (0)

Tatter\\Files
=============

[](#tatterfiles)

File uploads and management, for CodeIgniter 4

[![](https://github.com/tattersoftware/codeigniter4-files/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-files/actions/workflows/phpunit.yml)[![](https://github.com/tattersoftware/codeigniter4-files/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-files/actions/workflows/phpstan.yml)[![](https://github.com/tattersoftware/codeigniter4-files/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-files/actions/workflows/deptrac.yml)[![Coverage Status](https://camo.githubusercontent.com/e4eeac61167d4fd6f69e2ca787a2a73f38131a9d33b3e20308cff8c59c7e43ce/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746174746572736f6674776172652f636f646569676e69746572342d66696c65732f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/tattersoftware/codeigniter4-files?branch=develop)

Quick Start
-----------

[](#quick-start)

1. Install with Composer: `> composer require tatter/files`
2. Migrate the database: `> php spark migrate -all`
3. Seed the database: `> php spark db:seed "Tatter\Files\Database\Seeds\FileSeeder"`
4. Start managing files:

[![image](https://user-images.githubusercontent.com/17572847/96811765-ff82c500-13e9-11eb-9f1d-c9461ef1a438.png)](https://user-images.githubusercontent.com/17572847/96811765-ff82c500-13e9-11eb-9f1d-c9461ef1a438.png)[![image](https://user-images.githubusercontent.com/17572847/96811782-00b3f200-13ea-11eb-9f39-df56362e1d2b.png)](https://user-images.githubusercontent.com/17572847/96811782-00b3f200-13ea-11eb-9f39-df56362e1d2b.png)[![image](https://user-images.githubusercontent.com/17572847/96811800-01e51f00-13ea-11eb-8a2d-f06ae5dff469.png)](https://user-images.githubusercontent.com/17572847/96811800-01e51f00-13ea-11eb-8a2d-f06ae5dff469.png)

Features
--------

[](#features)

The Files module is a self-contained set of routes and functions that adds uploading and CRUD controls to any project. It uses [DropzoneJS](https://www.dropzonejs.com) for drag-and-drop uploads, and supports a number of extensions for generating file thumbnails and exporting files to various destinations.

Installation
------------

[](#installation)

Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:

```
> composer require tatter/files
```

Or, install manually by downloading the source files and adding the directory to **app/Config/Autoload.php**.

Once the files are downloaded and included in the autoload, run any library migrations to ensure the database is setup correctly:

```
> php spark migrate --all
```

Run the seeder to install necessary database settings:

```
php spark db:seed "Tatter\Files\Database\Seeds\FileSeeder"
```

Finally, run the framework's Publish Command to copy assets to your public directory:

```
php spark publish
```

**NOTE**: You may need to adjust your **Publisher.php** config file to support `.mjs` files.

Configuration (optional)
------------------------

[](#configuration-optional)

The library's default behavior can be altered by extending its config file. Copy **examples/Files.php** to **app/Config/** and follow the instructions in the comments. If no config file is found in **app/Config** the library will use its own.

**NOTE**: If your project is part of a tracking repository you probably want to add the file storage to your **.gitignore**

```
writable/files/*
!writable/files/index.html

```

Usage
-----

[](#usage)

Default routes:

- **files/index** - If user is allowed `mayList()` then shows all files, otherwise tries to fall back to the current logged in user
- **files/user/{userId}** - Shows files for a single user; if no user ID is supplied it defaults to the current logged in user
- **files/thumbnail/{fileId}** - Displays the thumbnail for a file

CRUD:

- **files/new** - Basic Dropzone form
- **files/upload** - Accepts AJAX upload requests from Dropzone
- **files/delete/{fileId}** - Removes a file
- **files/rename/{fileId}** - Accepts POST data to rename a file

Available formats:

- **?format=cards** - Default view with thumbnail on responsive layout
- **?format=list** - An efficient list of files in table format
- **?format=select** - Can be used to create selectable files, e.g. as part of a form

Access control
--------------

[](#access-control)

This library uses **Tatter\\Permits** to control access to files, both generally (list, create) and specifically per user or group. The super-permit `mayAdmin()` can be added to a user or group for global file access.

By default the **files/** routes are available as soon as the module is installed. In most cases you will want to use Route Filters to restrict some or all of the routes.

Extending
---------

[](#extending)

**Controllers/Files.php** is the heart of the module, using cascading options to choose which files to display when. This controller has a `setData()` method to allow you to intercept this process to provide your own settings at any point. Simply extend the controller to your own and then provide whatever changes you would like, followed by the `display()` method. E.g.:

```
