Php – Yii file upload issue


Couple of months ago,I developed a simple app using YII,one of the feature was to upload file.
The feature was working well in my dev machine,couple of days ago client found the file upload feature is not working in his server since deployment.

And after that I test my dev machine that was not working too.

My controller looks:

public function actionEntry() {
        if (!Yii::app()->user->isGuest) {
            $model = new TrackForm;

            if (isset($_POST['TrackForm'])) {
                $entry = new Track;
                try {
                  $entry->product_image = $_POST['TrackForm']['product_image'];
                    $entry->product_image = CUploadedFile::getInstance($model, 'product_image');

                    if ($entry->save()) {
                        if ($entry->product_image) {
                            $entry->product_image->saveAs($entry->product_image->name, '/trackshirt/uploads');

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

                        // redirect to success page
                } catch (Exception $e) {
                    echo 'Caught exception: ', $e->getMessage(), "\n";
            } else {
                $this->render('entry', array('model' => $model));

Model is like below:

class Track extends CActiveRecord
    public static function model($className=__CLASS__)
        return parent::model($className);

    public function tableName()
        return 'product_details';

My view looks:

            $form = $this->beginWidget('CActiveForm', array(
                        'id' => 'hide-form',
                        'enableClientValidation' => true,
                        'clientOptions' => array(
                            'validateOnSubmit' => true,
                        'htmlOptions' => array('enctype' => 'multipart/form-data'),

    <p class="auto-style2"><strong>Administration - Add New Product</strong></p>
    <table align="center" style="width: 650px"><td class="auto-style3" style="width: 250px">Product Image</td>

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


    <p class="auto-style1">

                <div style="margin-leftL:-100px;">
                <?php echo CHtml::submitButton('Submit New Product Form'); ?>

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

Any idea where is the problem?I tried to debug it but every time it returns Null.


Best Solution

this link may help you.Also dump CUploadedFile instance to check what is going on.