要验证单个文件(单个输入文件字段)在Yii中没有问题并且它运行良好:
public function rules() {
return CMap::mergeArray(parent::rules(), array(
array(
'image',
'file',
'allowEmpty'=>false,
'types'=>'pdf,jpg,gif,png',
'on' => 'CaseA, CaseB',
'maxSize'=>1024000,
'tooLarge' => 'Max File size is 1MB',
'message' => 'You have to upload a file at least'
),
....
....
如果图像是文件数组怎么办? Yii创建的Form-Elements看起来像这样(Firebug-Output):
<input type="file" id="MyFormModel[image][0]" name="MyFormModel[image][0]">
<input type="file" id="MyFormModel[image][1]" name="MyFormModel[image][1]">
我应该在规则中修改什么?一个简单的“图像[]”没有帮助。
编辑:解决方案
public function rules() {
return CMap::mergeArray(parent::rules(), array(
array(
'image',
'file',
'allowEmpty'=>false,
'types'=>'pdf,jpg,gif,png',
'on' => 'CaseA, CaseB',
'maxSize'=>1024000,
'maxFiles' => 5, // <----- THAT'S IT
'tooLarge' => 'Max File size is 1MB',
'message' => 'You have to upload a file at least'
),
....
....