2014-10-20 67 views
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。

回答

0

有兩種方法可以解決這個問題。

  1. 地方您在connector.php函數(myResize):

     
    public function myResze($cmd, $result, $args, $elfinder) 
    { 
        //other code 
    } 
    

然後設置 '綁定' 到:

'bind' => array(
    'upload resize' => 'myResize'); 
  • 在connector.php中定義你的類並獲得一個在'bind'中使用的實例。例如:
  •  
        class className 
        { 
         // other code 
    
         public function myResize($cmd, $result, $args, $elfinder) 
         { 
         // other code 
         } 
        } 
    

    之後從這個類創建一個對象:

    $obj = new className(); 
    

    然後設置 '綁定' 到該:

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

    這個例子中是有用的爲你:https://github.com/Studio-42/elFinder/wiki/Logging

    +0

    你不能把公共函數放在connector.php中,因爲它會超出class – ymakux 2015-04-06 00:56:47