Closed Kison closed 7 years ago
You need to make a custom validator, since ->tempName
is referring to another location
Example
<?php
namespace app\components\validators;
use Yii;
use yii\validators\FileValidator as BaseValidator;
class PluploadFileValidator extends BaseValidator
{
/**
* Checks if given uploaded file have correct type (extension) according current validator settings.
* @param UploadedFile $file
* @return bool
*/
protected function validateExtension($file)
{
$oldTempName = $file->tempName;
$file->tempName = Yii::getAlias( \sweelix\yii2\plupload\components\UploadedFile::$targetPath ) . DIRECTORY_SEPARATOR . $file->tempName;
$result = parent::validateExtension($file);
$file->tempName = $oldTempName;
return $result;
}
}
In a model
public function rules()
{
return array_merge(parent::rules(), [
...
['uploadedFile', 'app\components\validators\PluploadFileValidator', 'extensions' => ['jpg', 'png', 'jpe', 'jpeg'], 'maxFiles' => 1, 'maxSize' => 1024],
...
]);
}
Thanks )
Does anybody know how to validate files with this extension?