Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- /* DB connection*/
- require 'db.php';
- /* end connection */
- /* check connection */
- if (mysqli_connect_errno()) {
- printf("Connect failed: %s\n", mysqli_connect_error());
- exit();
- }
- /*registration sheck*/
- $submit=$_POST['submit'];
- $fullname=$_POST['fullname'];
- $phone=preg_replace('/[^0-9]/', '', $_POST['phone']);
- $phone = (int) $phone;
- $adress=$_POST['city'] . ' ' . $_POST['district'] . ' ' . $_POST['adress'];
- $friends=$_POST['friends'];
- $school=$_POST['school'];
- $info=$_POST['info'];
- $dob = $_POST['year']."-". $_POST['month']."-".$_POST['day'];
- function createThumb($upfile, $dstfile, $max_width, $max_height){
- $size = getimagesize($upfile);
- $width = $size[0];
- $height = $size[1];
- $x_ratio = $max_width / $width;
- $y_ratio = $max_height / $height;
- if( ($width <= $max_width) && ($height <= $max_height)) {
- $tn_width = $width;
- $tn_height = $height;
- } elseif (($x_ratio * $height) < $max_height) {
- $tn_height = ceil($x_ratio * $height);
- $tn_width = $max_width;
- } else {
- $tn_width = ceil($y_ratio * $width);
- $tn_height = $max_height;
- }
- if($size['mime'] == "image/jpeg"){
- $src = ImageCreateFromJpeg($upfile);
- $dst = ImageCreateTrueColor($tn_width, $tn_height);
- imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
- imageinterlace( $dst, true);
- ImageJpeg($dst, $dstfile, 100);
- } else if ($size['mime'] == "image/png"){
- $src = ImageCreateFrompng($upfile);
- $dst = ImageCreateTrueColor($tn_width, $tn_height);
- imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
- Imagepng($dst, $dstfile);
- } else {
- $src = ImageCreateFromGif($upfile);
- $dst = ImageCreateTrueColor($tn_width, $tn_height);
- imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
- imagegif($dst, $dstfile);
- }
- }
- if($submit){
- if(isset($_FILES['upload_Image']['name']) && $_FILES['upload_Image']['name']!=='') {
- $ext = substr($_FILES['upload_Image']['name'], strpos($_FILES['upload_Image']['name'],'.'), strlen($_FILES['upload_Image']['name'])-1);
- $imgNormal = 'img'.$id.$ext;
- $normalDestination = "../../photos/orignal/" . $imgNormal;
- $httprootmedium = "../../photos/resized/" . $imgNormal;
- move_uploaded_file($_FILES['upload_Image']['tmp_name'], $normalDestination);
- createThumb($normalDestination,$httprootmedium,300,150); #For 500x300 Image
- }
- $result = $db->query("INSERT INTO usr_table (fullname, dob, school, add_date, phone, adress, info, img) VALUES ('$fullname', '$dob', '$school', CURDATE(), '$phone', '$adress', '$info', '$imgNormal')") or die(printf("Səhv1: %s\n", $db->error));
- $new_user_id = $db->insert_id;
- $friend_arr = explode(',', $friends);
- foreach($friend_arr as $friend_name) {
- $friend_name = trim($friend_name);
- if (empty($friend_name)) {continue;}
- $result = $db->query( "SELECT id FROM usr_table WHERE fullname = '$friend_name' LIMIT 1");
- if (!$result) {
- die(printf("Səhv2: %s\n", $db->error));
- }
- if ($result->num_rows == 0) {
- echo "Bazada ".$friend_name ." adlı adam yoxdur ";
- header ("Location: index.php");
- exit;
- }
- else {
- $data = $result->fetch_array(MYSQLI_ASSOC);
- $friend_id = $data['id'];
- $success=$db->query( "INSERT INTO usrfrnd_table (user_id, friend_id) VALUES ('$new_user_id', '$friend_id')");
- if (!$success) {die(printf("Səhv3: %s\n", $db->error)); }
- }
- }
- header ("Location: ../../index.php");
- exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement