Cuploadedfile::getinstance() Not Getting File Instance

I’m trying to detect a file being uploaded for validation. I’m using uploadify to upload the image, that explains the custom json error handling. I’m having trouble…

    public function actionUpload () {

        //handle uploadify file upload

        if (Yii::app()->getRequest()->getIsPostRequest()) {

            $json = [];

            $form = new \MyModule\Models\Forms\TemplateUpload();

            $form->template_file = \CUploadedFile::getInstance($form, 'template_file');

            //shows that template_file was properly uploaded

            $json['$_FILES'] = print_r($_FILES, true); 

            //shows that no instance of template_file was uploaded

            $json['print_r'] = print_r(\CUploadedFile::getInstance($form, 'template_file'), true); 

            if (!$form->validate()) {

                $json['errors'] = $form->getErrors();


            echo json_encode($json);


            //return Yii::app()->end(); commented out since it also shows debug data


        if (is_numeric($this->request->getQuery('container'))) {

            Yii::app()->session->add('container', $this->request->getQuery('container'));


        $this->selectedStep = 2;


        $this->render('upload', array(

            'container' => Container::model()->findByPk(Yii::app()->session->get('container'))



There’s a breakdown somewhere in what’s happening because I keep getting a “Template is blank” error. How can I be sure that my form object properly sees the uploaded file?

I just realized that the upload field name is "template_file" NOT "TemplateUpload[template_file]"… I need to figure out how to get this to work with uploadify.


getInstanceByName() is what I needed… took me long enough to figure it out :-\