Hi every one,
i want to add a validation rule for uploading a file :
upload can accept any file extension except aspecefic list of extensions.
for example : i can upload any type of file except .exe
i look into documentation and i found that we can just give lis of file extensions that can be accepted.
file : CFileValidator, verifies if an attribute is receiving a valid uploaded file.
allowEmpty, whether the attribute requires a file to be uploaded or not.
maxFiles, the maximum file count the given attribute can hold.
maxSize, the maximum number of bytes required for the uploaded file.
minSize, the minimum number of bytes required for the uploaded file.
tooLarge, the error message used when the uploaded file is too large.
tooMany, the error message used if the count of multiple uploads exceeds limit.
tooSmall, the error message used when the uploaded file is too small.
types, a list of file name extensions that are allowed to be uploaded.
wrongType, the error message used when the uploaded file has an extension name that is not listed among extensions.
Any one have an idea ?
gusnips
(Gustavo)
February 22, 2011, 2:37pm
2
use a custom validator
//rules
array('myFile', 'myValidator')
public function myValidator()
{
$valid=strpos($this->myFile,'.exe')===false;
//use some kind of validation above
if(!$valid)
$this->addError('myFile', 'invalid extension');
}