Advertisement
Guest User

Untitled

a guest
Apr 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $errors = array();
  4. if (count($errors) > 0) : ?>
  5. <div class="error">
  6. <?php foreach ($errors as $error) : ?>
  7. <p><?php echo $error ?></p>
  8. <?php endforeach ?>
  9. </div>
  10. <?php endif;
  11. if(isset($_POST['reg'])) {
  12. $username = $_POST['username'];
  13. $email = $_POST['mail'];
  14. $password = $_POST['password'];
  15. $password2 = $_POST['password2'];
  16. if ($password != $password2) {
  17. echo "Passwords do not match";
  18. }
  19.  
  20. if (count($errors) == 0) {
  21. $map = "uploads/";
  22. $image = $map . basename($_FILES["pic"]["name"]);
  23. $continue = 1;
  24. $imageFileType = strtolower(pathinfo($image, PATHINFO_EXTENSION));
  25. // Check if image file is a actual image or fake image
  26. if (isset($_POST["pic"])) {
  27. $check = getimagesize($_FILES["pic"]["tmp_name"]);
  28. if ($check !== false) {
  29. echo "File is an image - " . $check["mime"] . ".";
  30. $continue = 1;
  31. } else {
  32. echo "File is not an image.";
  33. $continue = 0;
  34. }
  35. }
  36. if ($_FILES["pic"]["size"] > 500000) {
  37. echo "Sorry, your file is too large.";
  38. $continue = 0;
  39. } else {
  40. $file = fopen("users.txt", "a");
  41. }
  42. if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  43. && $imageFileType != "gif") {
  44. echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  45. $continue = 0;
  46. } else {
  47. $file = fopen("users.txt", "a");
  48. }
  49. if ($continue == 0) {
  50. echo "Sorry, your file was not uploaded.";
  51. } else {
  52. if (move_uploaded_file($_FILES["pic"]["tmp_name"], $image)) {
  53. echo "<p class='filesaved'>The file " . basename($_FILES["pic"]["name"]) . " has been uploaded.<br></p>";
  54. $file = fopen("users.txt", "a");
  55. } else {
  56. echo "Sorry, there was an error uploading your file.";
  57. }
  58. }
  59.  
  60. if (!$file) {
  61. echo "Cant find the file";
  62. }
  63. $user = htmlspecialchars($_POST['username']);
  64. $mail = htmlspecialchars($_POST['mail']);
  65. $password = htmlspecialchars($_POST['password']);
  66. $avatar = $image;
  67. $_SESSION["username"] = $user;
  68. $_SESSION["avatar"] = $avatar;
  69. $username = $_SESSION["username"];
  70. $data = $user . PHP_EOL . $mail . PHP_EOL . $password . PHP_EOL . $avatar . PHP_EOL . PHP_EOL;
  71.  
  72. $myObj->username = $user;
  73. $myObj->mail = $mail;
  74. $myObj->password = $password;
  75. $myObj->avatar = $avatar;
  76.  
  77. $myJSON = json_encode($myObj);
  78. fwrite($file, $myJSON);
  79. fclose($file);
  80. echo "<!DOCTYPE html>
  81. <html lang=\"en\">
  82. <head>
  83. <meta charset=\"UTF-8\">
  84. <title>Succes</title>
  85. <link rel=\"stylesheet\" href=\"styles.css\">
  86. </head>
  87. <body>
  88. <p class=\"succestext\">Succes</p>
  89. <script>
  90. window.setTimeout(
  91. function(){
  92. window.location.href = \"home.html\";
  93. }, 10000);
  94. </script>
  95. </body>
  96. </html>";
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement