edit_profile.php
if (isset($_POST["car"],$_POST["first_name"],$_POST["about"])){
$errors = array();
}
if (empty($_FILES["avatar"]["tmp_name"]) === false){
$file_ext = end(explode('.', $_FILES["avatar"]["name"]));
if (in_array(strtolower($file_ext), array('jpg', 'jpeg', 'png', 'gif')) === false) {
$errors[]='blablabla';
}
if (empty($errors)){
set_profile_info($_POST["car"],$_POST["first_name"],$_POST["about"], (empty($_FILES["avatar"]["tmp_name"])) ? false : $_FILES["avatar"]["tmp_name"]);
}
$user_info = array(
'car' =>htmlspecialchars($_POST["car"],ENT_QUOTES, 'cp1251' ),
'first_name' =>htmlspecialchars($_POST["first_name"],ENT_QUOTES, 'cp1251'),
'about' =>htmlspecialchars($_POST["about"],ENT_QUOTES, 'cp1251')
);
}else{
$user_info = fetch_user_info($_SESSION["user_id"]);
}
?>
<?php
if (isset($errors) === false){
echo'blablabla';
}else if (empty($errors)){
echo'Your profile updated';
}else{
echo'<ul><li>', implode('</li><li>',$errors),'</li></ul>';
}
?>
and here is function users.php //Updates the current profile users info
function set_profile_info($car,$first_name,$about,$avatar){
$car = mysql_real_escape_string(htmlspecialchars($car));
$username = mysql_real_escape_string(nl2br(htmlspecialchars($username)));
$about = mysql_real_escape_string(htmlspecialchars($about));
if (file_exists($avatar)){
$src_size = getimagesize($avatar);
if ($src_size["mime"] === 'image/jpeg'){
$src_img = imagecreatefromjpeg($avatar);
}else if
($src_size["mime"] === 'image/png'){
$src_img = imagecreatefrompng($avatar);
}else if
($src_size["mime"] === 'image/gif'){
$src_img = imagecreatefromgif($avatar);
}else{
$src_img = false;
}
if ($src_img !== false){
$thumb_width = 200;
if($src_size[0]<= $thumb_width){
$thumb = $src_img;
}else{
$new_size[0] = $thumb_width;
$new_size[1] = ($src_size[1] / $src_size[0]) * $thumb_width;
$thumb = imagecreatetruecolor($new_size[0], $new_size[1]);
imagecopyresampled($thumb, $src_img, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]);
}
imagejpeg($thumb,"{$GLOBALS["path"]}/uploads/avatars/{$_SESSION["user_id"]}.jpg");
}
}
also I tried to make it by move_uploaded file.but i dont know exactly was it correct or not