/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new UserAdmin(); //picture path $path = Yii::app()->basePath . '/../uploads/profile_picture'; if (!is_dir($path)) { mkdir($path); } if (isset($_POST['UserAdmin'])) { $model->attributes = $_POST['UserAdmin']; if ($model->validate()) { $model->password = SHA1($model->password); $model->registerDate = new CDbExpression('NOW()'); $model->activation = md5(microtime()); //Picture upload script if (@(!empty($_FILES['UserAdmin']['name']['profile_picture']))) { $model->profile_picture = $_POST['UserAdmin']['profile_picture']; if ($model->validate(array('profile_picture'))) { $model->profile_picture = CUploadedFile::getInstance($model, 'profile_picture'); } else { $model->profile_picture = ''; } $model->profile_picture->saveAs($path . '/' . time() . '_' . str_replace(' ', '_', strtolower($model->profile_picture))); $model->profile_picture = time() . '_' . str_replace(' ', '_', strtolower($model->profile_picture)); } if ($model->save()) { Yii::app()->user->setFlash('success', 'User has been created successfully'); $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }