Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. <?php
  2.  
  3. //connect to database
  4. require('dbConnect.php');
  5.  
  6. // Grab the profile data from the database
  7. if (!isset($_POST['username'])) {
  8. $query = "SELECT username, firstName, lastName, city, state, country, email, bio FROM capstone WHERE username = '$username'";
  9. }
  10. else {
  11. $query = "SELECT username, firstName, lastName, city, state, country, email, bio FROM capstone WHERE username = '" . $_POST['username'] . "'";
  12. }
  13. $data = mysqli_query($dbc, $query);
  14.  
  15.  
  16. if (mysqli_num_rows($data) == 1) {
  17. // The user row was found so display the user data
  18. $row = mysqli_fetch_array($data);
  19. echo '<table>';
  20. if (!empty($row['username'])) {
  21. echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>';
  22. }
  23. if (!empty($row['firstName'])) {
  24. echo '<tr><td class="label">First name:</td><td>' . $row['firstName'] . '</td></tr>';
  25. }
  26. if (!empty($row['lastName'])) {
  27. echo '<tr><td class="label">Last name:</td><td>' . $row['lastName'] . '</td></tr>';
  28. }
  29. if (!empty($row['city']) || !empty($row['state']) || !empty($row['country'])) {
  30. echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . ' ' . $row['country'] . '</td></tr>';
  31. }
  32. if (!empty($row['email'])) {
  33. echo '<tr><td class="label">Email:</td><td>' . $row['email'] . '</td></tr>';
  34. }
  35. if (!empty($row['bio'])) {
  36. echo '<tr><td class="label">Bio:</td><td>' . $row['bio'] . '</td></tr>';
  37. }
  38.  
  39. echo '</table>';
  40.  
  41.  
  42. if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) {
  43. echo '<p>Would you like to <a href="editProfile.php">edit your profile</a>?</p>';
  44. }
  45. // End of check for a single row of user results
  46. else {
  47. echo '<p class="error">There was a problem accessing your profile.</p>';
  48. }
  49. }
  50.  
  51.  
  52. ?>
  53. <script>
  54. $("form").submit(function(e){ //when form submit, trigger this function
  55. e.preventDefault(); //prevent form from submitting
  56. var formData = new FormData($(this)[0]);//grab what would've been submitted
  57. formData.append("submit",true); //"fake" pressing submit button
  58. $.ajax({url: "includes/gallery.php",
  59. type: "POST",
  60. data: formData,
  61. success: function(result){
  62. $("#dynamicContent").html(result);
  63. },
  64. error: function(result){
  65. $("#dynamicContent").html("Error!");
  66. },
  67. cache: false,
  68. contentType: false,
  69. processData: false,
  70. enctype: 'multipart/form-data'
  71. });
  72. });
  73. </script>
  74.  
  75.  
  76. <?php
  77.  
  78. $errors = array();
  79.  
  80.  
  81. // image and thumbnail directories
  82. $target_path = "../users/$_POST['username']";
  83. $thumb_path = "../users/$_POST['username']/thumbs";
  84.  
  85. //set thumbnail size
  86. $thumb_width = 200;
  87. $thumb_height = 160;
  88.  
  89. $dir = "../users/$_POST['username']";
  90.  
  91. //opens directory
  92. if ($opendir = opendir($dir)){
  93. //reads directory
  94. while ($file = readdir($opendir)){
  95. if ($file != "." && $file != "..")
  96.  
  97. echo "<a href='$dir/$file'><img src='$thumb_path/$file'></a><br>";
  98. }
  99.  
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
  106. //checks the name of the file uploaded and prints it out
  107. if(!empty($_FILES['pictureFile']['name'])){
  108. // php stores everything in a temp file
  109. if (move_uploaded_file($_FILES['pictureFile']['tmp_name'], $target_path."/" . $_FILES['pictureFile']['name']) === FALSE)
  110.  
  111.  
  112. echo "Could not move uploaded file to ".$target_path . htmlentities($_FILES['pictureFile']['name']) . "\"<br />\n";
  113. else{
  114. //thumbnail creator
  115. $fileName = $_FILES['pictureFile']['name'];
  116. $fileExplode = explode(".", $fileName);
  117. $file_ext = $fileExplode[count($fileExplode)-1]; //get extension
  118. $upload_image = $target_path."/".basename($fileName);
  119. $thumbnail = $thumb_path."/".$fileName;
  120. list($width, $height) = getimagesize($upload_image);
  121. $thumb_create = imagecreatetruecolor($thumb_width, $thumb_height);
  122. switch($file_ext){
  123. case 'jpg':
  124. $source = imagecreatefromjpeg($upload_image);
  125. break;
  126. case 'jpeg':
  127. $source = imagecreatefromjpeg($upload_image);
  128. break;
  129. case 'png':
  130. $source = imagecreatefrompng($upload_image);
  131. break;
  132. case 'gif':
  133. $source = imagecreatefromgif($upload_image);
  134. break;
  135. default:
  136. $errors[] = "Did not submit a valid image file";
  137. break;
  138. }
  139.  
  140. imagecopyresized($thumb_create, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
  141. switch($file_ext){
  142. case 'jpg' || 'jpeg':
  143. imagejpeg($thumb_create, $thumbnail, 100);
  144. break;
  145. case 'png':
  146. imagepng($thumb_create, $thumbnail, 100);
  147. break;
  148. case 'gif':
  149. imagegif($thumb_create, $thumbnail, 100);
  150. break;
  151. default:
  152. imagejpeg($thumb_create, $thumbnail, 100);
  153.  
  154. }
  155.  
  156. echo "Successfully uploaded ".$target_path." " . htmlentities($_FILES['pictureFile']['name']) . "\"<br />\n";
  157.  
  158. }
  159. }
  160.  
  161.  
  162.  
  163.  
  164.  
  165. ?>
  166.  
  167. <form method="post" enctype="multipart/form-data" action="">
  168. <input type="file" name="pictureFile"/>
  169. <input type="submit" name="submit" value="Upload"/>
  170. </form>
  171.  
  172.  
  173. <?php
  174.  
  175. //checking for errors
  176.  
  177. if (isset($_POST["submit"])){
  178. $errors = array();
  179. if (empty($file))
  180. $errors[] = "No file was chosen.";
  181. if (count($errors) > 0 ){
  182. foreach ($errors as $error)
  183. echo "Error: ".$error."<br/>";
  184. }
  185. }
  186.  
  187.  
  188.  
  189.  
  190. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement