this my code for creating a user:
static public function ctrCreateUser(){
if (isset($_POST["newUser"])) {
if (preg_match('/^[a-zA-Z0-9 ]+$/', $_POST["newName"]) &&
preg_match('/^[a-zA-Z0-9]+$/', $_POST["newUser"]) &&
preg_match('/^[a-zA-Z0-9]+$/', $_POST["newPasswd"])){
$photo = "";
if (isset($_FILES["newPhoto"]["tmp_name"])){
list($width, $height) = getimagesize($_FILES["newPhoto"]["tmp_name"]);
$newWidth = 500;
$newHeight = 500;
$folder = "views/img/users/".$_POST["newUser"];
mkdir($folder, 0755);
if($_FILES["newPhoto"]["type"] == "image/jpeg"){
$randomNumber = mt_rand(100,999);
$photo = "views/img/users/".$_POST["newUser"]."/".$randomNumber.".jpg";
$srcImage = imagecreatefromjpeg($_FILES["newPhoto"]["tmp_name"]);
$destination = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresized($destination, $srcImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($destination, $photo);
}
if ($_FILES["newPhoto"]["type"] == "image/png") {
$randomNumber = mt_rand(100,999);
$photo = "views/img/users/".$_POST["newUser"]."/".$randomNumber.".png";
$srcImage = imagecreatefrompng($_FILES["newPhoto"]["tmp_name"]);
$destination = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresized($destination, $srcImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagepng($destination, $photo);
}
}
$table = 'users';
$encryptpass = crypt($_POST["newPasswd"], '$2a$07$asxx54ahjppf45sd87a5a4dDDGsystemdev$');
$data = array('name' => $_POST["newName"],
'user' => $_POST["newUser"],
'password' => $encryptpass,
'profile' => $_POST["newProfile"],
'photo' => $photo);
$answer = UsersModel::mdlAddUser($table, $data);
if ($answer == 'ok') {
......................}
else{
..........}
}
}
complete code is here
with comments thanks.