Uploading Picture troubles

Hi,

I’m a new to yii, so I was following this tutorial.

when I try to upload picture it reports empty field even if it is not.

my _form view:

[font="Courier New"]<div class="form">

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

'id'=&gt;'picture-form',


'enableAjaxValidation'=&gt;false,


'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),

)); ?>

&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'path_to'); ?&gt;


	&lt;?php echo &#036;form-&gt;fileField(&#036;model,'path_to'); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'path_to'); ?&gt;


&lt;/div&gt;

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

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

[/font]

and here is my action method:

[font="Courier New"] public function actionCreate()

{


	&#036;model=new Picture;


	if(isset(&#036;_POST['Picture']))


	{


		&#036;model-&gt;attributes=&#036;_POST['Picture'];


		


		&#036;model-&gt;picture=CUploadedFile::getInstance(&#036;model,'path_to');


		if(&#036;model-&gt;save()){


			&#036;log-&gt;lwrite('in save'.&#036;model-&gt;picture);


			&#036;model-&gt;picture-&gt;saveAs(Yii::app()-&gt;basePath.'/&#46;&#46;/images/'.&#036;model-&gt;picture);


			&#036;this-&gt;redirect(array('view','id'=&gt;&#036;model-&gt;id));


			&#036;log-&gt;lclose();


		}


	}


	&#036;this-&gt;render('create',array(


		'model'=&gt;&#036;model,


	));


}[/font]

when I print_r($_FILES) everything what should be there is there

when I print_r($_POST) the field ‘path_to’ is empty and the validator probably is picking that one.

I’m probably missing something here and I’m clueless.

update:

I’ve noticed yii is using hidden field with the same name as file input, than attributes are read from $_POST, which is causing the engine reading empty hidden field.

I understand that the hidden field is there for update when user is not entering new picture.

Can anyone advice what is the best way of doing picture upload?

Best!

I have an active discussion and bug report regarding this issue:

http://www.yiiframework.com/forum/index.php/topic/33997-form-filefield-hidden-field-empty/

Yes, the hidden field is always empty (totally dumb). You will need to use your own hidden field, or correct the core framework file as I have done (read my posts).

You understand incorrectly that the hidden field is there for update when a new image is not uploaded. That is what we would expect, however its not possible for the hidden field to contain a value. I am still awaiting the dev team’s answer as to the purpose of the hidden field (I cannot see any).