我对 php yiiframework 很陌生。我有用户模型,其中包含用户基本信息,包括个人资料图像,但是当我为我的个人资料更新新图像时,我必须删除图像文件。我使用以下方法上传了文件。
public function actionUpdate()
{
$model=$this->loadModel($id);
$random = substr(number_format(time() * rand(),0,'',''),0,10);
if(isset($_POST['Users']))
{
$model->attributes=$_POST['Users'];
$uploadedFile=CUploadedFile::getInstance($model,'image_path');
$fileName = $milliseconds. '-' .$random;
$model->image_path = $fileName;
if($model->save())
$uploadedFile->saveAs(Yii::app()->basePath.'/../images/uploaded/'.$fileName);
$this->redirect(array('view','id'=>$model->id));
}
$data = PanXCore::getDataForCreateUser();
$userRoles = new UserRoles();
$this->render('create',array(
'model'=>$model,
'roles' => $data['roles'],
'userRoles' => $userRoles
));
}