Manoj
Manoj

Reputation: 67

Error Uploading File in yii Framework

  public function actionCreate()
    {
        $model=new Add;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['yt0']))
        {
            //$rnd = rand(0,9999);  // generate random number between 0-9999
            $model->attributes=$_POST['Add'];
            $uploadedFile=CUploadedFile::getInstance($model,'add_videolink');
            //$fileName = "{$rnd}-{$upenter code hereloadedFile}";  // random number + file name
            $model->add_videolink = $uploadedFile;
            // var_dump($model->save());exit();
            if($model->save())
            {
                if(!empty($uploadedFile))
                {
                    $uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads'.$fileName);

                }
                $this->redirect(array('admin'));
            }
        }

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

And when i tried to run this code it displays "move_uploaded_file():" The second argument to copy() function cannot be a directory'

Upvotes: 1

Views: 150

Answers (3)

Mahesh
Mahesh

Reputation: 58

I think u miss the "/" after uploads.And after that also if u still have the problem, then try uploading small size files.

Upvotes: 2

Sajin
Sajin

Reputation: 151

You missed a slash symbol on saveAs()

$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads/'.$fileName);

Upvotes: 0

TotPeRo
TotPeRo

Reputation: 6791

Try to add "/" after uploads:

From:

$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads'.$fileName);

to:

$uploadedFile->saveAs(Yii::app()->basePath.'/../images/Uploads/'.$fileName);

Upvotes: 0

Related Questions