r15*_*r15 2 php yii yii-components
我是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
));
}
Run Code Online (Sandbox Code Playgroud)
用unlink()例如
unlink(Yii::app()->basePath.'/../images/uploaded/'. $oldfile);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5282 次 |
| 最近记录: |