Change `mb_strlen($dir)` part to `mb_strlen($dir,Yii::app()->charset)`.