2014-10-20 63 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