PHPackages                             codekanzlei/cake-attachments - 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. codekanzlei/cake-attachments

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

codekanzlei/cake-attachments
============================

File Attachments plugin for CakePHP

v3.0.4(5y ago)369.4k↓39.2%5[2 issues](https://github.com/scherersoftware/cake-attachments/issues)3PHPPHP &gt;=7.1

Since Feb 10Pushed 3y ago2 watchersCompare

[ Source](https://github.com/scherersoftware/cake-attachments)[ Packagist](https://packagist.org/packages/codekanzlei/cake-attachments)[ RSS](/packages/codekanzlei-cake-attachments/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (33)Used By (3)

CakePHP 3 cake-attachments
==========================

[](#cakephp-3-cake-attachments)

[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)

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

[](#requirements)

You can find the requirements in `composer.json`.

- [ImageMagick](http://www.imagemagick.org/script/binary-releases.php) for resizing images
- [cake-frontend-bridge](https://github.com/scherersoftware/cake-frontend-bridge) for easy access to the current controller and action derived from the URL
- [ghostscript](http://ghostscript.com/download/) for pdf previews. On Mac OS X, you can install ghostscript via homebrew:

```
`brew install ghostscript`

```

CakePHP 3 File Attachments Handling

Note: This Plugin depends on the codekanzlei/cake-frontend-bridge Plugin.

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

[](#installation)

#### 1. require the plugin in your `composer.json`

[](#1-require-the-plugin-in-your-composerjson)

```
	"require": {
		...
		"codekanzlei/cake-attachments": "dev-master",
		...
	}

```

#### 2. Include the plugin using composer

[](#2-include-the-plugin-using-composer)

Open a terminal in your project directory and run the following command:

```
$ composer update

```

Setup &amp; Configuration
-------------------------

[](#setup--configuration)

#### 1. Load the plugin in your `config/bootstrap.php`

[](#1-load-the-plugin-in-your-configbootstrapphp)

```
Plugin::load('Attachments', ['bootstrap' => false, 'routes' => true]);

```

Also be sure to add the cake-frontend-bridge since it is required for this plugin to work properly.

```
Plugin::load('FrontendBridge', ['bootstrap' => false, 'routes' => true, 'autoload' => true]);

```

#### 2. Create a table `attachments` in your project database

[](#2-create-a-table-attachments-in-your-project-database)

Run the following sql-query on your project database. You can find it in the Plugin's `config/schema.sql` file.

```
CREATE TABLE `attachments` (
  `id` char(36) NOT NULL,
  `filepath` varchar(255) NOT NULL,
  `filename` varchar(255) NOT NULL,
  `filetype` varchar(45) NOT NULL,
  `filesize` int(10) NOT NULL,
  `model` varchar(255) NOT NULL,
  `foreign_key` char(36) NOT NULL,
  `tags` text,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

```

#### 3. Create additional folders in your project folder

[](#3-create-additional-folders-in-your-project-folder)

Open a terminal in your project directory and run these commands:

```
$ mkdir -p tmp/uploads
$ mkdir -p app_data/attachments

```

You might have to change the folder permissions for these folders depending on your environment. The application must have permissions to read and write data into them.

#### 4. Adding JavaScript files to your project

[](#4-adding-javascript-files-to-your-project)

In your `webroot/js/app/app_controller.js`, add the following key to the `baseComponents` Array:

```
'Attachments'

```

This grants the project permission to use the plugin's .js files

#### 5. Adding Attachments to your project

[](#5-adding-attachments-to-your-project)

In your `config/app.php`, add the following key:

```
'Attachments' => [
    'tmpUploadsPath' => ROOT . '/tmp/uploads/',
    'path' => ROOT . '/app_data/attachments/',
    'acceptedFileTypes' => '/\.(jpe?g|png)$/i',
    'autorotate' => false
],

```

Further possible filetypes you want to allow can be specified in the 'acceptedFileTypes' filed, such as `gif|jpe?g|png|pdf|docx|doc|xls|xlsx|tif|tiff|zip`

When setting autorotate to true, views and previews of picture attachments will be rotated depending on their EXIF data.

#### 6. Adding AttachmentHelper to your project

[](#6-adding-attachmenthelper-to-your-project)

In your `/serc/Controller/AppController.php`, add the following keys to the `public $helpers` Array:

```
'Attachments.Attachments',

```

As the cake-frontend-bridge Plugin is required for the Attachments Plugin to work properly, some further configuarion is needed. Add the following key to the `$helpers` Array:

```
'FrontendBridge' => ['className' => 'FrontendBridge.FrontendBridge'],

```

Use the FrontendBridge in your `AppController extends Controller`:

```
use \FrontendBridge\Lib\FrontendBridgeTrait;

```

Lastly, add the FrontendBridge-key to `public $components`

```
'FrontendBridge.FrontendBridge',

```

#### 7. Include Attachments in your default layout

[](#7-include-attachments-in-your-default-layout)

In your `src/Template/Layout/default.ctp`, you need to create a new div element that contains the UI-elements of the Attachments Plugin.

```
