Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <?php
  2. $avatar;
  3. if ($_POST['name'] != null){
  4. $userName = $_POST['name'];
  5. }
  6. if ($_POST['city'] != null ) {
  7. $userCity = $_POST['city'];
  8. }
  9. if ($_POST['desc'] != null){
  10. $userDesc = $_POST['desc'];
  11. }
  12. $host = 'localhost';
  13. $baza = 'test';
  14. $uzytkownik = 'adam';
  15. $haslo = 'aaaaa5';
  16. if ($_POST['login'] != null && $_POST['pass'] != null && $_POST['mail'] != null) {
  17. $userLogin = $_POST['login'];
  18. $userPass = $_POST['pass'];
  19. $userMail = $_POST['mail'];
  20. $len = 20;
  21. $userID = substr(sha1(rand(1,10000)),0,$len);
  22. echo $userID;
  23. if($_FILES['image']['error']!=4){
  24. $avatar = fileReceive();
  25. }
  26. reg();
  27.  
  28. }
  29. else
  30. {
  31. header("Location: ../reg.php?reg=false");
  32. }
  33. function reg(){
  34. global $userID, $userMail, $userPass, $userLogin, $userDesc, $userCity, $userName, $avatar
  35. try {
  36.  
  37.  
  38.  
  39. $conn = new PDO("mysql:host=$host;dbname=$baza", $uzytkownik, $haslo);
  40. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  41. $stmt = $conn->prepare("SELECT Nazwa FROM Users WHERE Nazwa = '$userLogin'");
  42. $stmt->execute();
  43. $row = $stmt->fetch();
  44. if($userLogin != row[0]){
  45. $stmt = $conn->prepare("INSERT INTO 'Users' ('ID', 'Nazwa','Haslo', 'mail','name','city', 'image', 'desc', 'activate', 'admin') VALUES ('$userID','$userLogin', '$userPass', '$userMail', '$userName', '$userCity, $avatar', '$userDesc','false','false')";
  46. $stmt->execute();
  47.  
  48. sendMail();
  49.  
  50. }
  51.  
  52. else{
  53. header("Location: ../reg.php?reg=userexists");
  54. }
  55. }
  56. catch(PDOException $e)
  57. {
  58. return 1; #brak polaczenia
  59. }
  60. }
  61.  
  62.  
  63.  
  64.  
  65. function fileReceive(){
  66. $max_size = 1024*1024;
  67. if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
  68. if ($_FILES['filename']['size'] > $max_size) {
  69. echo 'Błąd! Plik jest za duży!';
  70. }
  71. else {
  72. echo 'Odebrano plik. Początkowa nazwa: '.$_FILES['filename']['name'];
  73. echo '<br/>';
  74.  
  75. if (isset($_FILES['filename']['type'])) {
  76. echo 'Typ: '.$_FILES['filename']['type'].'<br/>';
  77. }
  78.  
  79. $strExt = substr( $_FILES['filename']['name'], strrpos( $_FILES['filename']['name'], '.' ) + 1 );
  80. echo "Rozszerzenie: ". $strExt;
  81. $len = 20;
  82. $randstring = substr(sha1(rand(1,10000)),0,$len).".jpg";
  83. echo $randstring;
  84. echo $_FILES['filename']['name'];
  85.  
  86. if ($strExt == 'jpg' || 'JPG' || 'jpeg' || 'JPEG'){
  87. move_uploaded_file($_FILES['filename']['tmp_name'],
  88. $_SERVER['DOCUMENT_ROOT'].'../avatars/'.$_FILES['filename']['name']);
  89.  
  90. }
  91. else{
  92. echo "niy!!";}
  93. }
  94. }
  95. else {
  96. echo 'Błąd przy przesyłaniu danych!';
  97. }
  98. rename('avatars/'.$_FILES['filename']['name'], 'avatars/'.$randstring);
  99. return $randstring;
  100. }
  101.  
  102. function sendMail(){
  103. ob_start();
  104. $addressee = 'ajjambor912@gmail.com';
  105. @$email = $_POST['email'];
  106.  
  107. @$content = 'Name'' Content: '.$_POST['message'];
  108.  
  109. $header = "From: ".$_POST['email']." \nContent-Type:".
  110. ' text/plain;charset="iso-8859-2"'.
  111. "\nContent-Transfer-Encoding: 8bit";
  112. if (mail($addressee, 'Message from NAhandyman: ', $content , $header))
  113.  
  114. header('Location:../sended.php?send=true');
  115. else
  116. header('Location:../sended.php?send=false');
  117. }
  118.  
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement