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()
{
$model=new Pix;
// uncomment the following code to enable ajax-based validation
if(isset($_POST['ajax']) && $_POST['ajax']==='pix-upload-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['Pix']))
{
$model->attributes=$_POST['Pix'];
$model->image=CUploadedFile::getInstance($model,'image');
$file= Yii::app()->theme->baseUrl.'/images/'.$model->image->name;
if($model->save())
{
$model->image->saveAs('$file');
// redirect to success page
$this->redirect(array('pix/upload'));
}
}
$this->render('upload',array('model'=>$model));
}