file upload error

I get this error when I try to upload a file in the ‘images’ directory inside my theme folder ‘fitness’.

PHP Error

move_uploaded_file($file) [<a href=‘function.move-uploaded-file’>function.move-uploaded-file</a>]: failed to open stream: Permission denied

/home/ubc/Documents/yii/framework/web/CUploadedFile.php(183)

public function saveAs($file,$deleteTempFile=true)

179 {

180 if($this->_error==UPLOAD_ERR_OK)

181 {

182 if($deleteTempFile)

183 return move_uploaded_file($this->_tempName,$file);

184 else if(is_uploaded_file($this->_tempName))

185 return copy($this->_tempName, $file);

186 else

187 return false;

188 }

189 else

190 return false;

191 }

here is the code of upload action:

public function actionUpload()

    {


            &#036;model=new Pix;





         // uncomment the following code to enable ajax-based validation


        


           if(isset(&#036;_POST['ajax']) &amp;&amp; &#036;_POST['ajax']==='pix-upload-form')


           {


                  echo CActiveForm::validate(&#036;model);


                  Yii::app()-&gt;end();


           }


        





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


            {


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





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


                  &#036;file= Yii::app()-&gt;theme-&gt;baseUrl.'/images/'.&#036;model-&gt;image-&gt;name;


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


                  {


                         &#036;model-&gt;image-&gt;saveAs('&#036;file');


                         // redirect to success page


                         &#036;this-&gt;redirect(array('pix/upload'));


                  }





                 


            }


           &#036;this-&gt;render('upload',array('model'=&gt;&#036;model));


   }

The target directory is writeable by the HTTP server process?

yes, it is writable.

Is safe mode turned on, if it is writeable but not owned by the HTTP server process then it wont work in safe mode. PHP is saying it can’t access one of the files/locations, so something is wrong at the file system level.

You might not notice that




$model->image->saveAs('$file');



It should be




$model->image->saveAs($file);



thanks! it is working now on making this subtle change suggested by you.

Welcome…