Advertisement
Guest User

Untitled

a guest
Jun 19th, 2011
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. /* DB connection*/
  4. require 'db.php';
  5. /* end connection */
  6. /* check connection */
  7. if (mysqli_connect_errno()) {
  8.     printf("Connect failed: %s\n", mysqli_connect_error());
  9.     exit();
  10. }
  11.  
  12. /*registration sheck*/
  13. $submit=$_POST['submit'];
  14. $fullname=$_POST['fullname'];
  15. $phone=preg_replace('/[^0-9]/', '', $_POST['phone']);
  16. $phone =  (int) $phone;
  17. $adress=$_POST['city']  . ' ' .  $_POST['district'] . ' ' . $_POST['adress'];
  18. $friends=$_POST['friends'];
  19. $school=$_POST['school'];
  20. $info=$_POST['info'];
  21. $dob = $_POST['year']."-". $_POST['month']."-".$_POST['day'];
  22.  
  23.  
  24. function createThumb($upfile, $dstfile, $max_width, $max_height){
  25.    $size = getimagesize($upfile);
  26.    $width = $size[0];
  27.    $height = $size[1];
  28.    $x_ratio = $max_width / $width;
  29.    $y_ratio = $max_height / $height;
  30.    if( ($width <= $max_width) && ($height <= $max_height)) {
  31.            $tn_width = $width;
  32.            $tn_height = $height;
  33.    } elseif (($x_ratio * $height) < $max_height) {
  34.            $tn_height = ceil($x_ratio * $height);
  35.            $tn_width = $max_width;
  36.    } else {
  37.            $tn_width = ceil($y_ratio * $width);
  38.            $tn_height = $max_height;
  39.    }
  40.    if($size['mime'] == "image/jpeg"){
  41.            $src = ImageCreateFromJpeg($upfile);
  42.            $dst = ImageCreateTrueColor($tn_width, $tn_height);
  43.            imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
  44.            imageinterlace( $dst, true);
  45.            ImageJpeg($dst, $dstfile, 100);
  46.    } else if ($size['mime'] == "image/png"){
  47.            $src = ImageCreateFrompng($upfile);
  48.            $dst = ImageCreateTrueColor($tn_width, $tn_height);
  49.            imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
  50.            Imagepng($dst, $dstfile);
  51.  
  52.    } else {
  53.  
  54.            $src = ImageCreateFromGif($upfile);
  55.            $dst = ImageCreateTrueColor($tn_width, $tn_height);
  56.            imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height,$width, $height);
  57.            imagegif($dst, $dstfile);
  58.    }
  59. }
  60.  
  61.  
  62.  
  63. if($submit){
  64. if(isset($_FILES['upload_Image']['name']) && $_FILES['upload_Image']['name']!=='') {
  65.     $ext = substr($_FILES['upload_Image']['name'], strpos($_FILES['upload_Image']['name'],'.'), strlen($_FILES['upload_Image']['name'])-1);
  66.  
  67.     $imgNormal = 'img'.$id.$ext;
  68.     $normalDestination = "../../photos/orignal/" . $imgNormal;
  69.      $httprootmedium = "../../photos/resized/" . $imgNormal;
  70.      move_uploaded_file($_FILES['upload_Image']['tmp_name'], $normalDestination);
  71.     createThumb($normalDestination,$httprootmedium,300,150); #For 500x300 Image
  72. }
  73.  
  74. $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));
  75.  
  76. $new_user_id = $db->insert_id;
  77. $friend_arr = explode(',', $friends);
  78. foreach($friend_arr as $friend_name) {
  79. $friend_name = trim($friend_name);
  80. if (empty($friend_name)) {continue;}
  81. $result = $db->query( "SELECT id FROM usr_table WHERE fullname = '$friend_name' LIMIT 1");
  82. if (!$result) {
  83. die(printf("Səhv2: %s\n", $db->error));  
  84.  }
  85.    
  86.     if ($result->num_rows == 0) {
  87.         echo "Bazada ".$friend_name ." adlı adam yoxdur ";
  88.         header ("Location: index.php");
  89.         exit;
  90.     }
  91.     else {
  92.     $data = $result->fetch_array(MYSQLI_ASSOC);
  93.     $friend_id = $data['id'];
  94.     $success=$db->query( "INSERT INTO usrfrnd_table (user_id, friend_id) VALUES ('$new_user_id', '$friend_id')");
  95.         if (!$success) {die(printf("Səhv3: %s\n", $db->error)); }
  96.     }
  97. }
  98. header ("Location: ../../index.php");
  99. exit;
  100. }
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement