0

200x100 ではなく、アップロード中に別の画像サイズを変更したい。ただし、この調整を行うための関連ファイルが見つかりません。

いくつかの検索の後、複数の人が他の人にconnector.phpを調べるように言っているのを見ました。このファイルでは、次の行に沿って何かを渡す必要があります。

$opts = array(
            'bind' => array(
                'upload resize' => array($this, 'myResize')
            ),
            'roots' => array(
                array(...)
            )
        );

/**
     * Upload/resize callback catcher, resizes image to 320x240px/240x320px respectively, keeps ratio
     *
     * @param  string   $cmd       command name
     * @param  array    $result    command result
     * @param  array    $args      command arguments from client
     * @param  object   $elfinder  elFinder instance
     * @return true     Forces elFinder to sync all events
     * */
    public function myResize($cmd, $result, $args, $elfinder) {
        $files = $result['added'];
        foreach ($files as $file) {
            $arg = array(
                'target' => $file['hash'],
                'width' => 320,
                'height' => 320,
                'x' => 0,
                'y' => 0,
                'mode' => 'propresize',
                'degree' => 0
            );
            $elfinder->exec('resize', $arg);
        }

        return true;
    }

私の大きな質問は次のとおりです。

この関数をどこに配置しますか? Symfony2 の (FM)ElfinderBundle を使用しています。

4

1 に答える 1

1

この問題を解決するには 2 つの方法があります。

  1. 関数 (myResize) を connector.php に配置します。

    public function myResze($cmd, $result, $args, $elfinder)
    {
      //その他のコード
    }
    

次に、「バインド」を次のように設定します。

'bind' => array(
    'upload resize' => 'myResize');
  1. connector.php でクラスを定義し、「バインド」で使用するためのインスタンスを取得します。例 :
    クラスクラス名
    {
       // その他のコード

       public function myResize($cmd, $result, $args, $elfinder)
       {
         // その他のコード
       }
    }

このクラスからオブジェクトを作成した後:

$obj = new className();

次に、「バインド」をこれに設定します。

'bind' => array(
    'upload resize' => array($obj, 'myResize'));

この例はあなたに役立ちます: https://github.com/Studio-42/elFinder/wiki/Logging

于 2015-03-09T08:30:58.927 に答える