Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. if (isset($_POST['gallery-upload'])) {
  4. $hostname='**';
  5. $username='**';
  6. $password='**';
  7. $file = $_FILES['image'] ['tmp_name'];
  8. $tmpName = $_FILES['image']['tmp_name'];
  9. $filter = $_POST['filter'];
  10.  
  11. $fp = fopen($tmpName, 'rb');
  12.  
  13. try {
  14. $dbh = new PDO("mysql:host=$hostname;dbname=dddoecje_campu",$username,$password);
  15. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
  16. $stmt = $dbh->prepare("INSERT INTO `gallery`(`id`, `image`, `filter`) VALUES ('',:image,:filter)");
  17. $stmt->bindParam(':filter', $filter);
  18. $stmt->bindParam(':image', $fp, PDO::PARAM_LOB);
  19. $dbh->errorInfo();
  20. $stmt->execute();
  21. // use exec() because no results are returned
  22. header("Location: index.php");
  23.  
  24. }
  25. catch(PDOException $e)
  26. {
  27. echo $sql . "<br>" . $e->getMessage();
  28. }
  29.  
  30. $dbh = null;
  31. }
  32. ?>
  33.  
  34. <div class="col-md-4">
  35. <div class="panel panel-default">
  36. <div class="panel-body">
  37. <form action="upload-gallery.php" method="post" enctype="multipart/form-data">
  38. <div class="form-group">
  39. <i class="icon-cloud-upload"></i>
  40. <span>Select file</span>
  41. <input type="file" accept="image/png, image/jpeg, image/gif" data-max-size="5000" name="image">
  42. </div>
  43. <select name="filter">
  44. <option value="all">All</option>
  45. <option value="area">Area</option>
  46. <option value="resort">Resort</option>
  47. <option value="rinjani">Rinjani</option>
  48. </select>
  49. <button style="margin-top: 10px;" name="gallery-upload" class="btn btn-default"><?php echo $upload_gallery;?></button>
  50. </form>
  51. </div>
  52. </div>
  53. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement