如何在Yii的fileimagearbehavior扩展中上传多个图像

时间:2014-05-18 18:24:24

标签: php image-processing yii yii-extensions

我尝试为Yii使用fileimagearbehavior扩展,并且它没有很多文档。在示例中,我刚刚发现如何上传1个文件,但我无法找到如何上传1个以上文件的方法。这里的例子

class Dish extends CActiveRecord {
    public $recipeImg; // used by the form to send the file.

    public function rules()
        {
        return array(
                // ...
                // for the form too
                array('recipeImg', 'file', 'types' => 'png, gif, jpg', 'allowEmpty' => true),
               // ...
            );
        }

      public function behaviors() {
            return array(
               'recipeImgBehavior' => array(
                   'class' => 'ImageARBehavior',
                    'attribute' => 'recipeImg', // this must exist
                    'extension' => 'png, gif, jpg', // possible extensions, comma separated
                    'prefix' => 'img_',
                    'relativeWebRootFolder' => 'files/recipes', // this folder must exist

                    # 'forceExt' => png, // this is the default, every saved image will be a png one.
                    # Set to null if you want to keep the original format

                    'useImageMagick' => '/usr/bin', # I want to use imagemagick instead of GD, and
                    # it is located in /usr/bin on my computer.

                        // this will define formats for the image.
                    // The format 'normal' always exist. This is the default format, by default no
                    // suffix or no processing is enabled.
                    'formats' => array(
                        // create a thumbnail grayscale format
                        'thumb' => array(
                            'suffix' => '_thumb',
                            'process' => array('resize' => array(60, 60), 'grayscale' => true),
                        ),
                               // create a large one (in fact, no resize is applied)
                        'large' => array(
                             'suffix' => '_large',
                        ),
                        // and override the default :
                        'normal' => array(
                           'process' => array('resize' => array(200, 200)),
                         ),
                     ),
                    'defaultName' => 'default', // when no file is associated, this one is used by getFileUrl
                   // defaultName need to exist in the relativeWebRootFolder path, and prefixed by prefix,
                   // and with one of the possible extensions. if multiple formats are used, a default file must exist
                   // for each format. Name is constructed like this :
                   //     {prefix}{name of the default file}{suffix}{one of the extension}
                )
           );
     }
}

这里有一个观点:      echo $form->fileField($model,'recipe');

0 个答案:

没有答案