Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. // Create MySQL login values and
  3.  
  4. // set them to your login information.
  5.  
  6. $username = "root";
  7.  
  8. $password = "";
  9.  
  10. $host = "localhost";
  11.  
  12. $database = "imageprocessor";
  13.  
  14.  
  15. // Make the connect to MySQL or die
  16.  
  17. // and display an error.
  18.  
  19. $link = mysqli_connect($host, $username, $password);
  20.  
  21. if (!$link) {
  22.  
  23. die('Could not connect: ' . mysqli_error());
  24.  
  25. }
  26.  
  27.  
  28. // Select your database
  29.  
  30. mysqli_select_db ($link,$database);
  31.  
  32.  
  33.  
  34. // Make sure the user actually
  35.  
  36. // selected and uploaded a file
  37.  
  38. if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
  39.  
  40. // Temporary file name stored on the server
  41.  
  42. $tmpName = $_FILES['image']['tmp_name'];
  43.  
  44.  
  45. // Read the file
  46.  
  47. $fp = fopen($tmpName, 'r');
  48.  
  49. $data = fread($fp, filesize($tmpName));
  50.  
  51. $data = addslashes($data);
  52.  
  53. fclose($fp);
  54.  
  55.  
  56.  
  57. // Create the query and insert
  58.  
  59. // into our database.
  60.  
  61. $query = "INSERT INTO tbl_images ";
  62.  
  63. $query .= "(image) VALUES ('$data')";
  64.  
  65. $results = mysqli_query($link,$query);
  66.  
  67.  
  68. // Print results
  69.  
  70. echo "Thank you, your file has been uploaded.";
  71.  
  72.  
  73. }
  74.  
  75. else {
  76.  
  77. echo "No image selected/uploaded";
  78.  
  79. }
  80.  
  81.  
  82. // Close our MySQL Link
  83.  
  84. mysqli_close($link);
  85.  
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement