[SOLVED]Validation is not returning an error

Hey everyone,

I am using a BLOB datatype in my database to store uploaded files. That is working well they are uploading and storing properly, and they can be reconstructed.

The problem I am having is in validation. I require the files to ONLY be in .ZIP format. So I applied the validation rule:

array('uploadedFile', 'file', 'types'=>'zip' ,'allowEmpty'=>false,'wrongType'=>'File must be in .ZIP format!'),

It is only partially working :confused:

If the file is not in .zip format it will not upload it or store it in the database, but it wont display an error message.

Here is the code pertaining to the uploader:


public function actionUpload()


		$model=new TsPlusFiles;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);












public function rules()


		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('uploadedFile', 'file', 'types'=>'zip' ,'allowEmpty'=>false,'wrongType'=>'File must be in .ZIP format!'),




	* Saves the name, size, type and data of the uploaded file


	public function beforeSave() {

		if($file=CUploadedFile::getInstance($this,'uploadedFile')) {






		return parent::beforeSave();




<div class="form">

                        <?php $form=$this->beginWidget('CActiveForm', array(







                        )); ?>


                    <p class="note">Fields with <span class="required">*</span> are required.</p>


		    <?php echo $form->errorSummary($model); ?>


                    <div class="row">

                        <?php echo $form->labelEx($model,'uploadedFile'); ?>

			<?php echo $form->fileField($model,'uploadedFile'); ?>

			<?php echo $form->error($model,'uploadedFile'); ?>



                    <div class="row buttons">

                        <?php echo CHtml::submitButton('Submit'); ?>



                    <?php $this->endWidget(); ?>


                    </div><!-- form -->

I have tried it with and without client side validation, and I still get the same result, it wont upload the file, but it also won’t display an error message.

I wanted to see exactly what was happening if nothing gets added to the database. If the file has an incorrect extension it isn’t added (which is great) however it doesn’t display the error message.

SO I altered some of the code in my controller:








If I don’t put anything for upload (leave the field blank) it redirects me to ‘index’

HOWEVER if I try and upload a file with an invalid extension it still redirects me to ‘upload’

somehow it is passing validation and getting saved, even though its not saving… ??? :( ???

I have no idea what is going on. Something tells me it is an inherent problem with the CfileValidator not being able to pass an error message once the form has been submitted.


I had been testing the upload script with a file that was larger than the upload_max_filesize in my php.ini file.

Noticing this I ran some tests on CFileValidator. It turns out that if you try and upload a file that is larger than the upload_max_filesize (as set in php.ini) then the validator will not return ANY error messages.

Personally I think this is something that should be looked into.