Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require_once "inc/package.inc.php";
  4. include "connect.php";
  5.  
  6.  
  7. //Ga er vanuit dat het formulier correct is ingevuld
  8. $correct = true;
  9.  
  10. //Sla de waarden op in een variabel
  11.  
  12. $title = $_POST['title'];
  13. if(isset($_POST['title']) && $_POST['title'] != ''){
  14. $title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
  15. $correct = true;
  16. } else {
  17. echo "<p id='popupr'>Geef een titel!</p>";
  18. $correct = false; //Toch een foute waarde, onthou dit!
  19. }
  20.  
  21. $blog = $_POST['reactie'];
  22. if(isset($_POST['reactie']) && $_POST['reactie'] != ''){
  23. $blog = filter_var($_POST['reactie'], FILTER_SANITIZE_STRING);
  24. $correct = true;
  25. } else {
  26. $correct = false; //Toch een foute waarde, onthou dit!
  27. }
  28.  
  29. $mobiel = $_POST['mobiel'];
  30. if(isset($_POST['mobiel']) && $_POST['mobiel'] != ''){
  31. $mobiel = filter_var($_POST['mobiel'], FILTER_SANITIZE_STRING);
  32. $correct = true;
  33. } else {
  34. $correct = false; //Toch een foute waarde, onthou dit!
  35. }
  36.  
  37. $tweet = $_POST['hashtag'];
  38. if(isset($_POST['hashtag']) && $_POST['hashtag'] != ''){
  39. $blog = filter_var($_POST['hashtag'], FILTER_SANITIZE_STRING);
  40. $correct = true;
  41. } else {
  42. $correct = false; //Toch een foute waarde, onthou dit!
  43. }
  44.  
  45. if(isset($_POST['btn_upload'])) {
  46. $img = $_FILES["file_img"];
  47. $filetmp = $_FILES["file_img"]["tmp_name"];
  48. $priority = 2;
  49. if (empty($img)) {
  50. $filename === null;
  51. $target === null;
  52.  
  53. } else {
  54. $file = $_FILES["file_img"]["name"];
  55. $filetype = $_FILES["file_img"]["type"];
  56. // unieke toevoeging berekenen
  57. $uniqueId = uniqId();
  58.  
  59. // een hash van het bestand, of data in bestand
  60. $hash = sha1_file($filetmp);
  61.  
  62. $filename = "image_".$uniqueId."-".$hash.".png";
  63. $target = realPath("photo").DIRECTORY_SEPARATOR.$filename;
  64.  
  65. move_uploaded_file($filetmp,$target);
  66. }
  67.  
  68. $correct = true;
  69. }
  70.  
  71. //Was alles correct ingevuld?
  72. if($correct){
  73. // voeg de reactie toe in de tabel blogs.
  74. $author = $_SESSION["name"];
  75.  
  76. // voeg de reactie toe in de tabel blogs.
  77. include "datum.php";
  78.  
  79. try{
  80. $stmt = $connection->prepare("INSERT INTO blogs(author, date, title, blog, mobiel, hashtag, priority, img_name, img_path) VALUES (:author, :date, :title, :blog, :mobiel, :hashtag, :priority, '$filename', '$target')");
  81. $stmt->bindValue(':author', $author);
  82. $stmt->bindValue(':date', $datum);
  83. $stmt->bindValue(':title', $title);
  84. $stmt->bindValue(':blog', $blog);
  85. $stmt->bindValue(':mobiel', $mobiel);
  86. $stmt->bindValue(':hashtag', $tweet);
  87. $stmt->bindValue(':priority', $priority);
  88. }
  89. catch(PDOException $e)
  90. {
  91. echo $e;
  92. }
  93. $result = $stmt->execute();
  94. if(!$result) {
  95. print_r($stmt->errorInfo());
  96. } else {
  97. header('Location: index.php');
  98. exit;
  99. }
  100.  
  101. } else {
  102. //Er is ergens een foute waarde ingevoerd, geef de bezoeker de mogelijkheid om terug te gaan
  103. echo "<p>Er is een foute waarde ingevoerd, <a href="javascript:history.back();">ga terug</a>.</p>";
  104. }
  105.  
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement