PHPackages                             satthi/contents-file - 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. satthi/contents-file

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

satthi/contents-file
====================

CakePHP ContentsFile

5.1.0(2mo ago)597.4k↓35.2%11MITPHP

Since Apr 4Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/satthi/Contents-file)[ Packagist](https://packagist.org/packages/satthi/contents-file)[ Docs](https://github.com/satthi/Contents-file)[ RSS](/packages/satthi-contents-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (78)Used By (0)

Contents-file
=============

[](#contents-file)

このプラグインはCakePHP5用ファイルアップロードツールです。

インストール
------

[](#インストール)

composer.json

```
{
	"require": {
		"satthi/contents-file": "*"
	}
}

```

`composer install`

使い方
---

[](#使い方)

### (初期設定・ローカルファイル保存の場合)

[](#初期設定ローカルファイル保存の場合)

① 設定を記述 bootstrap.phpなど

```
Configure::write('ContentsFile.Setting', [
    'type' => 'normal',
    // trueでファイル名がランダム文字列に
    'randomFile' => true,
    // trueで拡張子付きでファイルを保存する。loaderを通さずに使用する場合は設定しておいたほうが良い。
    'ext' => true,
    'Normal' => [
        'tmpDir' => TMP . 'cache/files/',
        'fileDir' => ROOT . '/files/',
    ],
]);
```

② プラグイン読込 Application.php

```
public function bootstrap()
{
    $this->addPlugin('Migrations');
    // 追加
    $this->addPlugin('ContentsFile', ['routes' => true]);
}
```

③ tmpDir及びfileDirを権限777で準備

### (初期設定・S3保存の場合)

[](#初期設定s3保存の場合)

① 設定を記述 bootstrap.phpなど

```
Configure::write('ContentsFile.Setting', [
    'type' => 's3',
    // trueでファイル名がランダム文字列に
    'randomFile' => true,
    // trueで拡張子付きでファイルを保存する。awsの場合は別途ヘッダーを吐き出すため設定する必要性はあまり高くない。
    'ext' => true,
    'S3' => [
        'key' => 'KEY',
        'secret' => 'SECRET',      // IAM Roleを利用する場合、省略可能
        'bucket' => 'BUCKET_NAME', // IAM Roleを利用する場合、省略可能
        'tmpDir' => 'tmp',
        'fileDir' => 'file',
        'workingDir' => TMP,
        // ファイルのURLをloaderを通さず直接awsに接続したい場合に設定
        /*
        //s3-ap-northeast-1.amazonaws.com/BUCKET_NAME でも
        //BUCKET_NAME.s3-website-ap-northeast-1.amazonaws.com でも
        //指定の文字列.cloudfront.net でも使用したいものを設定
        */
        'static_domain' => '//s3-ap-northeast-1.amazonaws.com/BUCKET_NAME',
        // minio 使用時にendpointを使用
        //'endpoint' => 'http://{{ip_address}}:9000',
    ]
]);
```

② プラグイン読込 Application.php

```
public function bootstrap()
{
    // 追加
    $this->addPlugin('ContentsFile', ['routes' => true]);
}
```

③ workingDirを権限777で準備

④ S3のｊバケットを準備し、IAMの権限について以下を設定

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::BUCKET_NAME",
                "arn:aws:s3:::BUCKET_NAME/*"
            ]
        }
    ]
}

```

※ 作業するbucketについてs3:GetObject、s3:PutObject、s3:DeleteObject、s3:ListBucketの権限があれば良いです

### 各種基本設定(共通)

[](#各種基本設定共通)

マイグレーション実行

`ContentsFile/config/Migrations/20161109095904_AttachmentsAdd`

にファイルを置いているので利用してください。

※topicsを例とする Table

```
