Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <td><select name="img_lvm" id="img_lvm" >
  2. <option>--Select--</option>
  3. <?php
  4. $hostname = "xxx";
  5. $user = "xxx";
  6. $password = "xxx";
  7. $db = "xxx";
  8. $conn = mysqli_connect($hostname, $user, $password, $db);
  9.  
  10. $result = mysqli_query($conn, "select luchtvaartmaatschappijID, luchtvaartmaatschappij from tbl_luchtvaartmaatschappij WHERE inactive='0' Order by luchtvaartmaatschappij ASC");
  11. while($row = mysqli_fetch_array($result))
  12. {
  13. $lvID = $row['luchtvaartmaatschappijID'];
  14. $l = $row['luchtvaartmaatschappij'];
  15. $iata = $row['IATACode'];
  16. echo "<option value='$lvID'>$iata - $l</option>";
  17. }mysqli_close($conn);
  18. ?>
  19. </select></td>
  20.  
  21. <?php
  22. error_reporting( ~E_NOTICE ); // avoid notice
  23. require_once 'dbconfig.php';
  24.  
  25. if(isset($_POST['btnsave']))
  26. {
  27. $location = $_POST['img_location'];// location where photo was taken
  28. $lvm = $_POST['img_lvm'];// airline of photo
  29. $date = date('Y-m-d', strtotime($_POST['img_date'])); // date of photo
  30. $img_t = $_POST['img_t'];// aircraft in photo
  31. $img_nmr = $_POST['img_nmr'];// registration of aircraft in photo
  32. $img_comments = $_POST['img_comments'];// photo comments
  33.  
  34. $imgFile = $_FILES['img_file']['name'];
  35. $tmp_dir = $_FILES['img_file']['tmp_name'];
  36. $imgSize = $_FILES['img_file']['size'];
  37.  
  38.  
  39. if(empty($location)){
  40. $errMSG = "Please Enter Location where Photo Was Taken.";
  41. }
  42. else if(empty($lvm)){
  43. $errMSG = "Please Enter the Airline.";
  44. }
  45. else if(empty($img_t)){
  46. $errMSG = "Please Enter the Aircraft.";
  47. }
  48. else if(empty($imgFile)){
  49. $errMSG = "Please Select Image File.";
  50. }
  51. else
  52. {
  53.  
  54. $upload_dir = '/home/xxx/public_html/vg/img/random/' .$lvm . '/'; // upload directory
  55.  
  56. if (!is_dir('/home/xxx/public_html/vg/img/random/'.$lvm .'/')) {
  57. mkdir('/home/xxx/public_html/vg/img/random/' . $lvm .'/', 0777, TRUE);
  58.  
  59. }
  60.  
  61. $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
  62.  
  63. // valid image extensions
  64. $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
  65.  
  66. // rename uploading image
  67. $img_file = rand(1000000000,1000000000000).".".$imgExt;
  68.  
  69. // allow valid image file formats
  70. if(in_array($imgExt, $valid_extensions)){
  71. // Check file size '5MB'
  72. if($imgSize < 5000000) {
  73. move_uploaded_file($tmp_dir,$upload_dir.$img_file);
  74. }
  75. else{
  76. $errMSG = "Sorry, your file is too large.";
  77. }
  78. }
  79. else{
  80. $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  81. }
  82. }
  83.  
  84.  
  85. // if no error occured, continue ....
  86. if(!isset($errMSG))
  87. {
  88. $stmt = $DB_con->prepare('INSERT INTO tbl_random(img_location,img_lvm,img_file, img_date, img_t, img_nmr, img_comments) VALUES(:i_loc, :i_lvm, :img_file, :img_date, :img_t, :img_nmr, :img_comments)');
  89. $stmt->bindParam(':i_loc',$location);
  90. $stmt->bindParam(':i_lvm',$lvm);
  91. $stmt->bindParam(':img_file',$img_file);
  92. $stmt->bindParam(':img_date',$img_date);
  93. $stmt->bindParam(':img_t',$img_t);
  94. $stmt->bindParam(':img_nmr',$img_nmr);
  95. $stmt->bindParam(':img_comments',$img_comments);
  96.  
  97. if($stmt->execute())
  98. {
  99. $successMSG = "new record successfully inserted ...";
  100. header("refresh:1;index.php"); // redirects image view page after 1 seconds.
  101. }
  102. else
  103. {
  104. $errMSG = "error while inserting....";
  105. }
  106. }
  107. }
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement