File Storage Plugin

The FileStorage plugin provides a flexible file storage abstraction layer for CakePHP applications. It uses the FlySystem library to support multiple storage backends.

Features

  • Multiple Storage Backends: Local filesystem, AWS S3, FTP, Dropbox, and more
  • Automatic Image Resizing: Create multiple versions (thumbnails, medium, large) automatically
  • Image Optimization: Automatic file size optimization for faster loading
  • File Variants: Support for multiple versions of files with customizable operations
  • Metadata Storage: Store file information in the database
  • Collections: Organize files into logical groups
  • Path Builder: Flexible path generation with customizable templates

Storage Backend

This demo uses a Local Filesystem adapter, storing files in:
/var/www/dereuromark/sandbox5/webroot/files/uploads/

Examples

Images Auto-Resize

Upload and display image files with automatic thumbnail generation and optimization.

Try it
PDFs

Upload and manage PDF documents.

Try it
General Files

Upload any type of file.

Try it

Advanced Features

Image Cropping Advanced Interactive

Client-side image cropping with multiple aspect ratios, zoom, rotate, and real-time preview before upload.

Try it
Drag & Drop Upload Modern AJAX

Modern HTML5 drag-and-drop upload with progress tracking, previews, and client-side validation.

Try it

Image Processing

Image Variants Showcase Automatic

See how uploaded images are automatically processed into multiple sizes (thumbnail, medium, large). View the variants side-by-side with their metadata and file sizes.

View Variants Demo

Configuration

The plugin is configured in config/app_custom.php with the following setup:

  • Storage Adapter: Local filesystem
  • Path Template: {model}{ds}{collection}{ds}{randomPath}{ds}{id}{ds}{filename}.{extension}
  • Random Path Levels: 1 (for better directory distribution)
  • File Sanitization: URL-safe filenames with max length of 190 characters

Usage in Code

To use FileStorage in your own tables:

// In your Table class
$this->addBehavior('FileStorage.FileStorage', [
    'fields' => [
        'file' => 'file',
    ],
]);

// In your controller
$entity = $this->MyModel->newEmptyEntity();
$entity = $this->MyModel->patchEntity($entity, $this->request->getData());
if ($this->MyModel->save($entity)) {
    // File is automatically processed and stored
}

CLI Commands

Regenerate image variants for existing files:

bin/cake file_storage generate_image_variant --verbose

Send your feedback or bugreport!