ajgkqsldxvkqsldkqs azelfkqsmkqsmlkdqsmld azmlekdqmskdmlqskd nkldsfkqsmldkqsmdmlskd decrypt($_POST['id']); /* Fetch the information */ $con = db_connect(); $sql = session($con,$session); $response['success'] = 0; $message = ""; if(db_rows($con,$sql)>0){ /* fetch userid and create session token */ $query = mysqli_query($con,$sql); while($row=mysqli_fetch_array($query)){ $userid = $row['userid']; $pic = $row['picture']; } /* Validate image */ $target_folder = "../clap/pics/"; if (isset($_FILES['image']['name'])) { $ext = strtolower(pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION)); $allowed_file = array('jpg', 'jpeg','png','gif'); /* give the file a new name */ $image = md5($userid.$_FILES['image']['name'].time()).".".$ext; $target_path = $target_folder.$image; $size = $_FILES['image']["size"]; if(!in_array($ext,$allowed_file)){ $response['message'] = $mcrypt->encrypt('Only jpg,jpeg,png or gif files is allowed!'); }else if($size>1000000){ $response['message'] = $mcrypt->encrypt('Image is too large. Maximum image size is 1MB!'); }else{ $quality = image_quality($size); compressImage($_FILES['image']['tmp_name'],$target_path,$quality); /* update logo and delete old log */ $sql = "update users set picture='".escape($con,$image)."' where id=".intval($userid); if(mysqli_query($con,$sql)){ $response['success'] = 1; /* Delete old image */ if(!empty($pic)){ unlink($target_folder.$pic); } $response['pic'] = $mcrypt->encrypt(pic_url($image)); }else{ $response['message'] = $mcrypt->encrypt('Server error. Please try again later.'); } } }else{ $response['message'] = $mcrypt->encrypt('No file received.'); } }else{ $response['message'] = $mcrypt->encrypt("You don't have right to access this content."); } echo json_encode($response); db_close($con); }