Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. /**
  2. @author : Shubham Maurya,
  3. Email id : maurya.shubham5@gmail.com
  4. **/
  5.  
  6. 1.Make a file in notepad and save it as index.php and paste the below code.
  7.  
  8. <?php
  9.  
  10. $DB_host = "localhost";
  11. $DB_name = "test";
  12. $DB_user = "root";
  13. $DB_pass = "";
  14.  
  15. try
  16. {
  17. $conn = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
  18. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19. echo "Done..";
  20. }
  21. catch(PDOException $e)
  22. {
  23. echo "ERROR : ".$e->getMessage();
  24. }
  25.  
  26. if(isset($_POST['register']))
  27. {
  28. //$image1=$_POST['image1'];
  29. //$ln=$_POST['image2'];
  30.  
  31. $imgFile = $_FILES['votercardimg']['name'];
  32. $tmp_dir = $_FILES['votercardimg']['tmp_name'];
  33. $imgSize = $_FILES['votercardimg']['size'];
  34.  
  35. $imgFile1 = $_FILES['adharimg']['name'];
  36. $tmp_dir1 = $_FILES['adharimg']['tmp_name'];
  37. $imgSize1 = $_FILES['adharimg']['size'];
  38.  
  39. $imgFile2 = $_FILES['ebillimg']['name'];
  40. $tmp_dir2 = $_FILES['ebillimg']['tmp_name'];
  41. $imgSize2 = $_FILES['ebillimg']['size'];
  42.  
  43. $imgFile3 = $_FILES['ecardimg']['name'];
  44. $tmp_dir3 = $_FILES['ecardimg']['tmp_name'];
  45. $imgSize3 = $_FILES['ecardimg']['size'];
  46.  
  47. $imgFile4 = $_FILES['otherimg']['name'];
  48. $tmp_dir4 = $_FILES['otherimg']['tmp_name'];
  49. $imgSize4 = $_FILES['otherimg']['size'];
  50.  
  51. $imgFile5 = $_FILES['drlincenceimg']['name'];
  52. $tmp_dir5 = $_FILES['drlincenceimg']['tmp_name'];
  53. $imgSize5 = $_FILES['drlincenceimg']['size'];
  54.  
  55. $upload_dir = 'images/'; // upload directory
  56. $upload_dir1 = 'images/'; // upload directory
  57. $upload_dir2 = 'images/'; // upload directory
  58. $upload_dir3 = 'images/'; // upload directory
  59. $upload_dir4 = 'images/'; // upload directory
  60. $upload_dir5 = 'images/'; // upload directory
  61.  
  62. $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
  63. $imgExt1 = strtolower(pathinfo($imgFile1,PATHINFO_EXTENSION)); // get image extension
  64. $imgExt2 = strtolower(pathinfo($imgFile2,PATHINFO_EXTENSION)); // get image extension
  65. $imgExt3 = strtolower(pathinfo($imgFile3,PATHINFO_EXTENSION)); // get image extension
  66. $imgExt4 = strtolower(pathinfo($imgFile4,PATHINFO_EXTENSION)); // get image extension
  67. $imgExt5 = strtolower(pathinfo($imgFile5,PATHINFO_EXTENSION)); // get image extension
  68.  
  69. // valid image extensions
  70. $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
  71.  
  72. // rename uploading image
  73. $userpic = rand(1000,1000000).".".$imgExt;
  74. $userpic1 = rand(1000,1000000).".".$imgExt1;
  75. $userpic2 = rand(1000,1000000).".".$imgExt2;
  76. $userpic3= rand(1000,1000000).".".$imgExt3;
  77. $userpic4 = rand(1000,1000000).".".$imgExt4;
  78. $userpic5 = rand(1000,1000000).".".$imgExt5;
  79.  
  80. // allow valid image file formatss
  81. if(in_array($imgExt, $valid_extensions) & in_array($imgExt1, $valid_extensions) & in_array($imgExt2, $valid_extensions) & in_array($imgExt3, $valid_extensions) & in_array($imgExt4, $valid_extensions) & in_array($imgExt5, $valid_extensions)){
  82. // Check file size '5MB'
  83. if($imgSize < 5000000 & $imgSize1 < 5000000 & $imgSize2 < 5000000 & $imgSize3 < 5000000 & $imgSize4 < 5000000 & $imgSize5 < 5000000) {
  84. move_uploaded_file($tmp_dir,$upload_dir.$userpic);
  85. move_uploaded_file($tmp_dir1,$upload_dir.$userpic1);
  86. move_uploaded_file($tmp_dir2,$upload_dir.$userpic2);
  87. move_uploaded_file($tmp_dir3,$upload_dir.$userpic3);
  88. move_uploaded_file($tmp_dir4,$upload_dir.$userpic4);
  89. move_uploaded_file($tmp_dir5,$upload_dir.$userpic5);
  90. try
  91. {
  92. $stmt=$conn->prepare("INSERT into image(image1,image2) VALUES(:image1,:image2)");
  93. if($stmt->execute(array(':image1'=>$userpic,':image2'=>$userpic1)))
  94. {
  95. echo "insert";
  96. }
  97.  
  98.  
  99. }
  100. catch (PDOException $e)
  101. {
  102. echo $e->getMessage();
  103. }
  104. }
  105. else{
  106. echo '<script type="text/javascript">alert("Your File is too Large")</script>';
  107. }
  108. }
  109. else{
  110. echo '<script type="text/javascript">alert("Sorry, only JPG, JPEG, PNG & GIF files are allowed.")</script>';
  111.  
  112. }
  113.  
  114. }
  115. ?>
  116.  
  117. <html>
  118. <body>
  119.  
  120. <div class="container">
  121.  
  122. <div class="row">
  123.  
  124. <div class="col-lg-8 col-lg-offset-2">
  125.  
  126. <form method="post" role="form" enctype="multipart/form-data">
  127.  
  128. <div class="col-md-6">
  129. <div class="form-group">
  130. <label for="form_name">Upload the Image1</label>
  131. <div style="line-height: 2.5;">
  132.  
  133. <p><input type="file" name="votercardimg" /></p>
  134.  
  135. </div>
  136. </div>
  137. </div>
  138.  
  139.  
  140. <div class="col-md-6">
  141. <div class="form-group">
  142. <label for="form_name">Upload the Image2</label>
  143. <div style="line-height: 2.5;">
  144.  
  145. <p><input type="file" name="adharimg" /></p>
  146. <p><input type="file" name="ebillimg" /></p>
  147. <p><input type="file" name="ecardimg" /></p>
  148. <p><input type="file" name="otherimg" /></p>
  149. <p><input type="file" name="drlincenceimg" /></p>
  150.  
  151. </div>
  152. </div>
  153. </div>
  154. <input type="submit" name="register">
  155.  
  156. </form>
  157.  
  158. </div><!-- /.8 -->
  159.  
  160. </div> <!-- /.row-->
  161.  
  162. </div> <!-- /.container-->
  163.  
  164. </body>
  165. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement