Guest User

Untitled

a guest
Feb 1st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['submitForm'])) {
  3. $firstname = $_POST['firstname'];
  4. $lastname = $_POST['lastname'];
  5. $email = $_POST['email'];
  6. $organisation = $_POST['organisation'];
  7. $question_1 = $_POST['question1'];
  8. $question_2 = $_POST['question2'];
  9. $question_3 = $_POST['question3'];
  10. $question_4 = $_POST['question4'];
  11. $question_5 = $_POST['question5'];
  12. $image_1 = $_POST['fileToUpload1'];
  13. $image_2 = $_POST['fileToUpload2'];
  14. $image_3 = $_POST['fileToUpload3'];
  15. $message = $_POST['message'];
  16.  
  17. $target_dir = "/var/www/vhosts/system/removed.co.uk/etc/contact-facility/uploads/";
  18. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  19. $uploadOk = 1;
  20. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  21. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  22.  
  23. if($check !== false) {
  24. $uploadOk = 1;
  25. }
  26.  
  27. else {
  28. $uploadOk = 0;
  29. }
  30.  
  31. if (file_exists($target_file)) {
  32. $uploadOk = 0;
  33. }
  34.  
  35. if ($_FILES["fileToUpload"]["size"] > 500000) {
  36. echo "Sorry, your file is too large.";
  37. $uploadOk = 0;
  38. }
  39.  
  40. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
  41. echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  42. $uploadOk = 0;
  43. }
  44.  
  45. $servername = "localhost";
  46. $username = "removed";
  47. $password = "removed";
  48. $dbname = "removed";
  49.  
  50. try {
  51. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  52. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  53. $sql = "INSERT INTO contact_facility (first_name, last_name, email_address, hospital_trust, question_1, question_2, question_3, question_4, question_5, image_1, image_2, image_3, message) VALUES ('$firstname', '$lastname', '$email', '$organisation', '$question_1', '$question_2', '$question_3', '$question_4', '$question_5', '$image_1', '$image_2', '$image_3', '$message')";
  54. $conn->exec($sql);
  55.  
  56. $success = "<p style='color: green;'>Thank you for contacting REMOVED.<br /><br />We have received your Contact Enquiry and will contact you within 24-48 hours with information regarding your request.</p>";
  57. }
  58.  
  59. catch(PDOException $e) {
  60. echo $sql . "<br />" . $e->getMessage();
  61. }
  62.  
  63. $conn = null;
  64. }
  65. ?>
  66.  
  67. $target_dir = "uploads/";
  68. $target_inner = "uploads/".$email;
  69. $img_inner = mkdir($target_inner);
  70.  
  71. if($img_inner=='1'){
  72. $target_file = $target_inner ."/" . basename($_FILES["fileToUpload"]["name"]);
  73. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  74. }
  75.  
  76. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  77. $uploadOk = 1;
  78.  
  79. // Check if $uploadOk is set to 0 by an error
  80. if ($uploadOk == 0) {
  81. $_SESSION['errMsg'] = "error in uploading image";
  82. header('location: register.php');
  83. // if everything is ok, try to upload file
  84. }
  85.  
  86. // Check if file already exists
  87. if (file_exists($target_file)) {
  88. $_SESSION['errMsg'] = "Sorry, file already exists.";
  89. $uploadOk = 0;
  90. header('location: register.php');
  91. }
  92. // Check file size
  93. if ($_FILES["fileToUpload"]["size"] > 100000) {
  94. $_SESSION['errMsg'] = "Sorry, your file is too large.";
  95. $uploadOk = 0;
  96. header('location: register.php');
  97. }
  98. // Allow certain file formats
  99. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" ) {
  100. echo "Sorry, only jpg, jpeg and png files are allowed.";
  101. $uploadOk = 0;
  102.  
  103. }
  104.  
  105. else
  106. {
  107. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  108. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  109. }
  110. else {
  111. echo "Sorry, there was an error uploading your file.";
  112. }
  113.  
  114. if($uploadOk==1)
  115. {
  116.  
  117. $sql = "INSERT INTO(your querry)
  118. // iam sure it will work
Add Comment
Please, Sign In to add comment