add a custom rule like this:
array('document', 'docTypeRuleValidator'),
then create that custom validation rule inside components/validators
with the name docTypeRuleValidator
as:
class DocTypeRuleValidator extends CValidator
{
public function validateAttribute($model, $attribute)
{
yii::trace($attribute, __METHOD__);
yii::trace(CVarDumper::dumpAsString($_FILES), __METHOD__);
if(in_array($_FILES['ModHwTM']['type']['imageUploaded'], array('image/jpg')))
{
$this->addError($model, $attribute, 'Not appropiate type!');
}
}
}
the trick here is to find the exact parameter of the Files array you want to use to validate type, following php zend certification specs is not enough to use Files, cause it could be manipulated by the user so this is a first validation ... if it pass then you should to check the temp file you have uploaded to make sure it is the type you support, but it is a great start i think.
For example i have made a test an the $_files array returns:
array
(
'ModHwTM' => array
(
'name' => array
(
'imageUploaded' => 'crude_widnows.jpg'
)
'type' => array
(
'imageUploaded' => 'image/jpeg'
)
'tmp_name' => array
(
'imageUploaded' => '/tmp/phpcYm2Vo'
)
'error' => array
(
'imageUploaded' => 0
)
'size' => array
(
'imageUploaded' => 6527
)
)
)
please read: how $files works
you could use this example to create your own custom validator to check the temp file
Please add your comments...