Twitter bootstrap 以Yii格式上传图像

Twitter bootstrap 以Yii格式上传图像,twitter-bootstrap,yii,Twitter Bootstrap,Yii,我已经在Yii框架中实现了图像文件上传。它正在成功上传图像并存储到数据库中,但图像未存储在我的目录中。在我的控制器中,我添加了以下代码: public function actionCreate() { $model=new Friends; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(is

我已经在Yii框架中实现了图像文件上传。它正在成功上传图像并存储到数据库中,但图像未存储在我的目录中。在我的控制器中,我添加了以下代码:

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

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

    if(isset($_POST['Friends']))
    {
        $model->attributes=$_POST['Friends'];

                 $image=CUploadedFile::getInstance($model,'profile_image');
             if (is_object($image) && get_class($image)==='CUploadedFile') 
                {
                  $model->profile_image=$image->name;    
                }
                if($model->save())
            if(is_object($image))
            $image->saveAs(dirname(__FILE__).'/../../friends_picture/'.$model->profile_image);   

        $this->redirect(array('view','id'=>$model->id));
    }

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

错误在哪里?给定的目录名是否正确?

请尝试此代码

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

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

    if(isset($_POST['Friends']))
    {
        $model->attributes=$_POST['Friends'];

        $model->profile_image = CUploadedFile::getInstance($model,'profile_image');

        if($model->save())

            $fullImgSource = Yii::getPathOfAlias('webroot').'/friends_picture/'.$model->profile_image;
            $model->profile_image->saveAs($fullImgSource);


        $this->redirect(array('view','id'=>$model->id));
    }

    $this->render('create',array(
        'model'=>$model,
    ));
}
愿它能帮助你

谢谢你试试这个

$model->profile_image=cuploaddedfile::getInstance($model,'profile_image')


dirname(文件)。'/../../friends\u picture/。$model->profile\u image响应此语句,查看这是要存储它的路径还是生成错误的路径。更新代码。再测试一次
    if($model->save())

        $fullImgSource = Yii::getPathOfAlias('webroot').'/friends_picture/'.$model->profile_image;
        $model->profile_image->saveAs($fullImgSource);