Guest User

Untitled

a guest
Dec 30th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. if(isset($_REQUEST['submit_request'])){
  2.  
  3. $insert_query= "INSERT INTO images SET text='$text',image='$image'";
  4.  
  5. $query= mysqli_query($connection,$insert_query);
  6.  
  7.  
  8.  
  9. echo '
  10. Success! uploaded image into the database!
  11.  
  12. ';
  13.  
  14. <?php
  15.  
  16. $dbhost = 'localhost';
  17. $dbUsername = 'root';
  18. $dbpassword = '';
  19. $dbname = 'photos';
  20.  
  21.  
  22. //Creating connection and selecting database
  23.  
  24. $db = new mysqli($dbhost,$dbUsername,$dbPassword,$dbName);
  25.  
  26. //Checking connection
  27.  
  28. if($db->connect_error){
  29. die("Connection failed:". $db->connect_error);
  30.  
  31. }
  32.  
  33.  
  34. //Getting image from the database
  35.  
  36. $result = $db->query("SELECT image FROM images WHERE id = {$_GET['id]}");
  37.  
  38. if($result->num_rows > 0){
  39. $imgData = $result->fetch_assoc();
  40.  
  41.  
  42. //Rendering Image
  43.  
  44. header("Content-type: image/jpg");
  45. echo $imgData["image"];
  46. }else{
  47. echo "Image not Found...";
  48. }
  49. }
Add Comment
Please, Sign In to add comment