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);
exit;
//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->includeUploadify();
$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?