Guest User

Untitled

a guest
Jan 8th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. session_start();
  2. include 'connection.php';
  3. $id=$_SESSION["id"];
  4.  
  5. if (!isset($_SESSION['id'])) {
  6. header("location:login.php");
  7. }
  8.  
  9. ?>
  10.  
  11. <?php
  12.  
  13. //DB Details
  14. $dbHost = 'localhost';
  15. $dbUsername = 'root';
  16. $dbPass = 'password';
  17. $dbName = 'images';
  18.  
  19. //Create connection and select DB
  20. $db = new mysqli ($dbHost, $dbUsername, $dbPass, $dbName);
  21.  
  22. if ($db->connect_error) {
  23. die ("Connection Failed: " . $db->connect_error);
  24. }
  25.  
  26. //Get image data from database
  27. $result = $db->query("SELECT image From images Where user_id=$id");
  28.  
  29. if ($result->num_rows > 0){
  30. $imgData = $result->fetch_assoc();
  31.  
  32. header("Content-type: image/jpeg");
  33. echo $imgData['image'];
  34. }else{
  35. echo "Image not found...";
  36. }
  37. ?>
Add Comment
Please, Sign In to add comment