Yii CMultiFileUpload限制图像宽度

时间:2014-11-24 13:59:19

标签: php yii

是否可以在CMultiFileUpload中限制图像宽度E.g宽度不小于500px

注意:我不是指Image maxSixe或minSize;

我的意思是Yii中有类似的东西
$image_info = getimagesize($_FILES["image"]["tmp_name"]);
$image_width = $image_info[0];
$image_height = $image_info[1];

这是我的CMultiFileUpload文件字段。

<?php
      $this->widget('CMultiFileUpload', array(
         'model'=>$model,
         'name'=>'image',
         'attribute'=>'image',
         'accept'=>'jpeg|jpg|gif|png',
         'denied'=>'Only jpg,gif and png are allowed', 
         'max'=>4,
        'remove'=>'[x]',
        'duplicate'=>'Already Selected',
        ));
     ?>

1 个答案:

答案 0 :(得分:0)

您可以在onFileSelect函数中设置大小

   $this->widget('CMultiFileUpload', 
    array(
'name' => 'property_floor_plans',
'model' => $model,                    
'max' => $fimgCount,
'accept' => 'jpeg|jpg|gif|png', // useful for verifying files
'duplicate' => 'Duplicate file!', // useful, i think
'denied' => 'Invalid file type', // useful, i think
'htmlOptions' => array('style' => "margin-left:15px;$options"),
                'options' => array(
                    'onFileSelect'=>'function(e ,v ,m){
                        var fileSize = e.files[0].size;
                        fileSize = (fileSize/1024);                           
                        if(fileSize>imgLimit){ 
                            alert("Exceeds file upload limit 2MB");                                
                            return false;
                        }                      
                        return true;
                    }',                        
                )
                ));