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

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

netcommons/files
================

Files for NetCommons Plugin

3.3.7.2(2y ago)093.4k3[17 issues](https://github.com/NetCommons3/Files/issues)15LicenseRef-NetCommonsPHP

Since Aug 29Pushed 1y ago14 watchersCompare

[ Source](https://github.com/NetCommons3/Files)[ Packagist](https://packagist.org/packages/netcommons/files)[ Docs](http://www.netcommons.org/)[ RSS](/packages/netcommons-files/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (6)Versions (40)Used By (15)

Files
=====

[](#files)

[![Tests Status](https://github.com/NetCommons3/Files/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Files/actions/workflows/tests.yml)[![Coverage Status](https://camo.githubusercontent.com/29f366e283ba5142fa60d264200b4e4906ac22591490d7928cb09630ce80a595/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4e6574436f6d6d6f6e73332f46696c65732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/NetCommons3/Files?branch=master)[![Stable Version](https://camo.githubusercontent.com/cf70f0e191c0912253e057bb20bc48c581216916dabf26356bef03f5b8484499/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6574636f6d6d6f6e732f66696c65732e7376673f6c6162656c3d737461626c65)](https://packagist.org/packages/netcommons/files)

AttachmentBehavior
==================

[](#attachmentbehavior)

ファイルアップロードをするフォームを表示するときはModel::recursiveを0以上にしてください。

Model::recursive = -1の場合、Modelに添付されたアップロードファイルの情報が取得できないため、NetCommonsForm::uploadFile()は添付されたファイルが無いと判断してしまいます。

認証キーと組み合わせ使う方法
==============

[](#認証キーと組み合わせ使う方法)

[認証キープラグイン](https://github.com/NetCommons3/AuthorizationKeys)と組み合わせることで特定の認証キーを知っているユーザだけがファイルダウンロード可能にできます。

リダイレクト型
-------

[](#リダイレクト型)

ダウンロードアクションを実装しているコントローラで AuthorizationKeyComponent を使います

```
public $components = array(
    'Files.Download',
    'AuthorizationKeys.AuthorizationKey' => [
        'operationType' => 'redirect',
        'targetAction' => 'download_pdf',
        'model' => 'BlogEntry',
    ],
);
```

ダウンロードアクション内で認証キーによるガードを設定します

```
public function download_pdf() {
    // ここから元コンテンツを取得する処理
    $this->_prepare();
    $key = $this->params['pass'][1];

    $conditions = $this->BlogEntry->getConditions(
            Current::read('Block.id'),
            $this->Auth->user('id'),
            $this->_getPermission(),
            $this->_getCurrentDateTime()
    );

    $conditions['BlogEntry.key'] = $key;
    $options = array(
            'conditions' => $conditions,
            'recursive' => 1,
    );
    $blogEntry = $this->BlogEntry->find('first', $options);
    // ここまで元コンテンツを取得する処理

    // 認証キーによるガード
    $this->AuthorizationKey->guard('redirect', 'BlogEntry', $blogEntry);

    // ダウンロード実行
    if ($blogEntry) {
        return $this->Download->doDownload($blogEntry['BlogEntry']['id'], ['filed' => 'pdf']);
    } else {
        // 表示できない記事へのアクセスなら404
        throw new NotFoundException(__('Invalid blog entry'));
    }
}
```

ポップアップ型
-------

[](#ポップアップ型)

ダウンロードアクションを実装しているコントローラで AuthorizationKeyComponent を使います

```
public $components = array(
    'Files.Download',
    'AuthorizationKeys.AuthorizationKey' => [
        'operationType' => 'redirect',
        'targetAction' => 'download_pdf',
        'model' => 'BlogEntry',
    ],
);
```

ダウンロードアクション内でのガードをpopupにします

```
    $this->AuthorizationKey->guard('popup', 'BlogEntry', $blogEntry);
```

ダウンロードリンクを書き換えてポップアップ画面が表示されるようにします。 認証キーポップアップはAngularJSのディレクティブ authorization-keys-popup-link として実装されています。

```

    PDF :
