[Solved] How To Upload A File Using A Model ?

hi guys

i have read this article yiiframework.com/wiki/2

and i have done everything step by step .

but it’s not working !

this is the model which i just copy and then paste :

class Item extends CActiveRecord


    public $image;

    // ... other attributes

    public function rules()


        return array(

            array('image', 'file', 'types'=>'jpg, gif, png'),




my view is exactly the same as the article :

$form = $this->beginWidget(



        'id' => 'upload-form',

        'enableAjaxValidation' => false,

        'htmlOptions' => array('enctype' => 'multipart/form-data'),



// ...

echo $form->labelEx($model, 'image');

echo $form->fileField($model, 'image');

echo $form->error($model, 'image');

// ...

echo CHtml::submitButton('Submit');


and my controller is :

class ItemController extends CController


    public function actionCreate()


        $model=new Item;








                // redirect to success page



        $this->render('create', array('model'=>$model));



when i choose an image(jpg , png , or something else) the controller doesn’t see my file , i mean isset($_FILES[‘Item’]) is false … i know it’s false because i check it with var_dump hundreds of times :

 public function actionCreate()


        $model=new Item;



i also test var_dump(isset($_FILES[‘Item’])) which was false either .

for every kinds of file(except plain txt file) $_POST[‘Item’]) remains empty.

i checked my request using firebug network panel(both firefox and chrome) and the request had the file .

what do you think ?

somebody ????

anybody ???

please help me :(

the problem wasn’t related to yii because same code works fine on another machine.

so i guess the problem is somewhat about Apache or Php configuration .

i don’t know what was the reason but i know it’s not about yii .

good luck

try to compare the php.ini on both machines.

to verify exactly what php.ini is being used (actually all of the .ini files ‘included’ - depending on OS and your environment), run phpinfo(), even in the Yii code, on both machines.