Advertisement
Guest User

KARELL

a guest
Jul 1st, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. <?php session_start();
  2.  
  3. if ( isset($_POST['afzender']) )
  4. {
  5. $_SESSION['afzender'] = $_POST['afzender'];
  6. }else{
  7. }
  8.  
  9. ?>
  10.  
  11. <html>
  12. <div class="header"> <h1>
  13. Chatbox
  14. </h1></div>
  15. <nav class="navbar navbar-inverse">
  16. <div class="container-fluid">
  17. <!-- Brand and toggle get grouped for better mobile display -->
  18. <div class="navbar-header">
  19. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  20. <span class="sr-only">Toggle navigation</span>
  21. <span class="icon-bar"></span>
  22. <span class="icon-bar"></span>
  23. <span class="icon-bar"></span>
  24. </button>
  25. <a class="navbar-brand" href="home.php">Chatbox</a>
  26. </div>
  27.  
  28. <!-- Collect the nav links, forms, and other content for toggling -->
  29. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  30. <ul class="nav navbar-nav">
  31. <li class="active"><a href="jdopperen.informatica.bc-enschede.nl/d/Chatbox/home.php">Chatbox <span class="sr-only">(current)</span></a></li>
  32. <li><a href="http://jdopperen.informatica.bc-enschede.nl/home/index.php">Home</a></li>
  33. <li><a href="http://jdopperen.informatica.bc-enschede.nl/d/Chatbox/">Verander Naam</a></li>
  34. </li>
  35. </ul>
  36. </li>
  37. </ul>
  38. </div><!-- /.navbar-collapse -->
  39. </div><!-- /.container-fluid -->
  40. </nav>
  41. <script type="text/javascript"
  42. src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  43. <head>
  44. <meta charset="utf-8">
  45. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  46. <meta name="viewport" content="width=device-width, initial-scale=1">
  47. <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  48. <meta name="description" content="">
  49. <meta name="author" content="">
  50. <link rel="icon" href="../../favicon.ico">
  51.  
  52. <title>Chatbox</title>
  53.  
  54. <!-- Bootstrap core CSS -->
  55. <link href="bootstrap.css" rel="stylesheet">
  56.  
  57. <!-- Custom styles for this template -->
  58. <link href="style.css" rel="stylesheet">
  59.  
  60. <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
  61. <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
  62. <script src="../../assets/js/ie-emulation-modes-warning.js"></script>
  63.  
  64. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  65. <!--[if lt IE 9]>
  66. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  67. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  68. <![endif]-->
  69. </head>
  70.  
  71. <body>
  72.  
  73. <?php
  74.  
  75. $servername = "localhost";
  76. $username = "jdopperen";
  77. $password = "ve4usWes";
  78. $dbname = "jdopperen";
  79.  
  80. // Create connection
  81. $conn = new mysqli($servername, $username, $password, $dbname);
  82. // Check connection
  83. if ($conn->connect_error) {
  84. die("Connection failed: " . $conn->connect_error);
  85. }
  86. if (isset ($_POST['bericht'])) {
  87. $sql = "INSERT INTO `chatbox_berichten`
  88. (`id`, `afzender`, `chatbox_id`, `bericht`, `timestamp`)
  89. VALUES (NULL, '".$_SESSION['afzender']."', '', '".$_POST['bericht']."', CURRENT_TIMESTAMP);";
  90. if ($conn->query($sql) === TRUE) {
  91. } else {
  92. echo $conn->connect_error;
  93. }
  94.  
  95. }
  96. echo "<div class='yolo'>";
  97. echo "<div class='main'>";
  98. $sql = "SELECT * FROM (
  99. SELECT * FROM chatbox_berichten ORDER BY id DESC LIMIT 20
  100. ) sub
  101. ORDER BY id ASC";
  102. $result = $conn->query($sql);
  103.  
  104. if ($result->num_rows > 0) {
  105. echo "<table>";
  106. // output data of each row
  107. while($row = $result->fetch_assoc()) {
  108. echo "<tr><td class='tabel'>" . $row["afzender"]. "<td class='bericht'>" . $row["bericht"]. " <td class='timestamp'>" . $row["timestamp"]. "</td></tr>";
  109. }
  110. echo "</table>";
  111. } else {
  112. echo "0 results";
  113. }
  114.  
  115.  
  116. ?>
  117. <form action="home.php" method="post" enctype="multipart/form-data">
  118. Select image to upload:
  119. <input type="file" name="fileToUpload" id="fileToUpload">
  120. <input type="submit" value="Upload Image" name="submit">
  121. </form>
  122.  
  123. </body>
  124. </html>
  125. <div id="file upload">
  126. <?php
  127. $target_dir = "uploads/";
  128. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  129. $uploadOk = 1;
  130. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  131. // Check if image file is a actual image or fake image
  132. if(isset($_POST["submit"])) {
  133. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  134. if($check !== false) {
  135. echo "";
  136. $uploadOk = 1;
  137. } else {
  138. echo "File is not an image.";
  139. $uploadOk = 0;
  140. }
  141. }
  142. // Check if file already exists
  143. if (file_exists($target_file)) {
  144. $uploadOk = 0;
  145. }
  146. // Check file size
  147. if ($_FILES["fileToUpload"]["size"] > 500000) {
  148. echo "Sorry, your file is too large.";
  149. $uploadOk = 0;
  150. }
  151. // Allow certain file formats
  152. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  153. && $imageFileType != "gif" ) {
  154. echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  155. $uploadOk = 0;
  156. }
  157. // Check if $uploadOk is set to 0 by an error
  158. if ($uploadOk == 0) {
  159. // if everything is ok, try to upload file
  160. } else {
  161. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  162. echo "";
  163. } else {
  164. echo "Sorry, there was an error uploading your file.";
  165. }
  166. }
  167. $image = basename( $_FILES["fileToUpload"]["name"]);
  168. $afzender = $_SESSION['afzender'];
  169. if ($uploadOk == 1) {
  170. $sql = "INSERT INTO chatbox_berichten (afzender, bericht) VALUES ('$afzender', '<img src=http://jdopperen.informatica.bc-enschede.nl/d/Chatbox/uploads/".$image.">')";
  171. if (!mysqli_query($conn, $sql)) {
  172. die('ER is eemn Error: ' . mysqli_error());
  173. }
  174.  
  175. }
  176. $conn->close();
  177. ?>
  178. <div class="zender">
  179. <div class="zender2">
  180. <form class="form1" action="home.php" method="post">
  181. <?php echo $_SESSION['afzender']; ?> <input type="text" name="bericht" required><br>
  182. <button>
  183. Verzend
  184. </button>
  185. </div>
  186.  
  187. </form>
  188. </div>
  189. </div>
  190.  
  191. </body>
  192.  
  193. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement