PHPackages                             burriko/cake-file-storage - 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. burriko/cake-file-storage

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

burriko/cake-file-storage
=========================

A basic file storage behavior for CakePHP. Handles storing uploaded files in database or file system.

v2.0.0(12y ago)101.1k[1 issues](https://github.com/burriko/cakephp-file-storage-behavior/issues)MITPHPPHP &gt;=5.3.0

Since Aug 10Pushed 11y ago2 watchersCompare

[ Source](https://github.com/burriko/cakephp-file-storage-behavior)[ Packagist](https://packagist.org/packages/burriko/cake-file-storage)[ Docs](https://github.com/burriko/cakephp-file-storage-behavior)[ RSS](/packages/burriko-cake-file-storage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

CakePHP File Storage Behavior [![Build Status](https://camo.githubusercontent.com/5a199bb33e09857f3e415cfad667b950e5c4d9be06f0e0811bc17400c53cfe19/68747470733a2f2f7472617669732d63692e6f72672f62757272696b6f2f63616b657068702d66696c652d73746f726167652d6265686176696f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/burriko/cakephp-file-storage-behavior)
============================================================================================================================================================================================================================================================================================================================================================================

[](#cakephp-file-storage-behavior-)

A file storage plugin for CakePHP 2.x. For the CakePHP 1.x behavior see the cakephp1 branch.

Handles attaching files to models and storing uploaded files in database or filesystem. If uploading to filesystem will store metadata in database.

Files saved in the filesystem will be saved in a directory hierarchy based on the hash of the file contents. Filenames are not used, so will never clash. The hierarchy is to ease performance issues when storing a very large number of files.

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

[](#installation)

If you're using composer then just add the following to your require block.

```
	"burriko/cake-file-storage": "2.1.*@dev"

```

If you're not, then clone/copy the contents of this directory to app/Plugins/CakeFileStorage.

Configure
---------

[](#configure)

1. Add the following line to your app/Config/bootstrap.php.

    ```
     CakePlugin::load('CakeFileStorage');

    ```
2. In your model add:

    ```
     public $actsAs = array('CakeFileStorage.FileStorage');

    ```
3. Your model's database schema will need fields for filename, type and size. If storing the file in the filesystem you will also need one named hash, and if storing in db one named content. Here is an example schema.

    ```
     CREATE TABLE `files` (
       `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
       `filename` varchar(100) NOT NULL,
       `type` varchar(100) NOT NULL,
       `size` mediumint(8) unsigned NOT NULL,
       `content` mediumblob NOT NULL,
       `hash` varchar(40) NOT NULL,
       `created` datetime NOT NULL,
       `modified` datetime NOT NULL,
       PRIMARY KEY (`id`)
     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ```

Usage
-----

[](#usage)

When saving this model, if there is a form field named 'file' it will be saved as a file using the behavior. By default it will be saved to the filesystem in an 'uploads' folder in the root folder of your app. The defaults can be changed by passing settings to the behavior as follows.

```
	public $actsAs = array(
		'CakeFileStorage.FileStorage' => array(
			'storage_type' => 'filesystem',
			'file_path' => '/path/to/files'
			'field_name' => 'my_file'
		)
	);

```

The behaviour also provides a validation message to check that the file uploaded without any problems. This can be used as follows.

```
	public $validate = array(
		'file' => array(
			'rule' => 'checkFileUpload',
			'message' => 'There was a problem uploading your file.'
		)
	);

```

You can retrieve the file from the model by using the fetchFile() method, and send the file back as a response by using the downloadFile() method of the FileStorage component. Here's an example controller that puts those together.

```
	class DocumentsController extends AppController
	{
		public $components = array('CakeFileStorage.FileStorage');

		public function download($id)
		{
			$document = $this->Document->fetchFile($id);

			return $this->FileStorage->createFileResponse($document);
		}
	}

```

When deleting a record the file will also be removed from disk, but only if no other record is pointing to the same file (because files are saved under a hash of their contents, if the same file was uploaded for multiple records they would all share the same file on disk).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% 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 ~0 days

Total

2

Last Release

4654d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c4d8ab979ef086342115d4e6e70f88a34cbfd17968ea57e222b9ab0445bba791?d=identicon)[burriko](/maintainers/burriko)

---

Top Contributors

[![graemetait](https://avatars.githubusercontent.com/u/64014?v=4)](https://github.com/graemetait "graemetait (43 commits)")[![tfohlmeister](https://avatars.githubusercontent.com/u/4696987?v=4)](https://github.com/tfohlmeister "tfohlmeister (1 commits)")

---

Tags

cakephpfilestorageuploadBehavior

### Embed Badge

![Health badge](/badges/burriko-cake-file-storage/health.svg)

```
[![Health](https://phpackages.com/badges/burriko-cake-file-storage/health.svg)](https://phpackages.com/packages/burriko-cake-file-storage)
```

###  Alternatives

[mohorev/yii2-upload-behavior

Upload behavior for Yii 2

128265.5k9](/packages/mohorev-yii2-upload-behavior)[yii-dream-team/yii2-upload-behavior

Yii2 file/image upload behavior for ActiveRecord

79207.1k16](/packages/yii-dream-team-yii2-upload-behavior)[dereuromark/cakephp-file-storage

This plugin is giving you the possibility to store files in virtually any kind of storage backend. This plugin is wrapping the Gaufrette library (https://github.com/KnpLabs/Gaufrette) library in a CakePHP fashion and provides a simple way to use the storage adapters through the StorageManager class.

104.1k](/packages/dereuromark-cakephp-file-storage)[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)

PHPackages © 2026

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