Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <?php
  2. $host = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $db_name = "db_php_school";
  6.  
  7. mysql_connect($host,$username,$password) or die("Database not connect");
  8. mysql_select_db($db_name) or die ("could not connect databse");
  9. error_reporting("E_ERROR_WORKING");
  10. echo "Database connecet success";
  11.  
  12.  
  13. ?>
  14.  
  15. <?php
  16.  
  17.  
  18. include './classes/image_class.php';
  19.  
  20. $obj_image = new Image();
  21.  
  22. if(@$_POST['Submit'])
  23. {
  24. $obj_image->image_name=str_replace("'", "''", $_POST['txt_image_name']);
  25. $obj_image->image=str_replace("'", "''", $_POST['txt_image']);
  26.  
  27. $obj_image->Insert_into_image();
  28.  
  29. $data_image=$obj_image->get_all_image_list();
  30. $row=mysql_num_rows($data_image);
  31. }
  32.  
  33. ?>
  34.  
  35. <!DOCTYPE html>
  36. <html>
  37. <head>
  38. <title>NOvaeye </title>
  39. </head>
  40. <body>
  41. <CENTER><H1>Novaeyewear</H1></CENTER>
  42. <CENTER><H2>Sunglass</H2></CENTER>
  43.  
  44. <CENTER>
  45. <form method="post" enctype="multipart/form-data">
  46. <table border="1" width="80%">
  47. <tr>
  48. <th width="50%">Image NAme</th>
  49. <td width="50%"><input type="text" name="txt_image_name"></input></td>
  50. </tr>
  51. <tr>
  52. <th width="50%">Upload IMage</th>
  53. <td width="50%"><input type="file" name="txt_image"></input></td>
  54. </tr>
  55. <tr>
  56. <td></td>
  57. <td width="50%"><input type="submit" name="Submit" value="Submit"></input></td>
  58. </tr>
  59. </table>
  60. </form>
  61. </CENTER>
  62.  
  63. <?php
  64. if($row!=0)
  65. {
  66. ?>
  67. <center>
  68. <table width="80%" border="1">
  69. <?php
  70. $icount = 1;
  71. while($data= mysql_fetch_assoc($data_image))
  72. {
  73. ?>
  74. <tr>
  75. <td style="text-align:center" style="width:10%;"><?php echo $icount; ?></td>
  76. <td style="text-align:center" style="width:20%;"><?php echo $data['image_name']?></td>
  77. <td style="text-align:center" style="width:50%;><img src="images/<?php echo $data['image']; ?>" width="400px" height="200px"></td>
  78. </tr>
  79. <?php
  80. $icount++;
  81. }
  82. ?>
  83. </table>
  84. </center>
  85. <?php
  86. }
  87.  
  88. ?>
  89. </body>
  90. </html>
  91.  
  92. <?php
  93. include 'db/db.php' ;
  94.  
  95. class Image{
  96.  
  97. var
  98. $image_id,
  99. $image_name,
  100. $image;
  101.  
  102. function Insert_into_image(){
  103. if(isset($_FILES['txt_image']))
  104. {
  105. $tempname = $_FILES['txt_image']['tmp_name'];
  106. $originalname =$_FILES['txt_image']['name'];
  107. $size =($_FILES['txt_image']['size']/5242888). "MB<br>";
  108. $type=$_FILES['txt_image']['type'];
  109. $image=$_FILES['txt_image']['name'];
  110. move_uploaded_file($_FILES['txt_image']['tmp_name'],"images/".$_FILES['txt_image']['name']);
  111. }
  112.  
  113.  
  114. $query = "Insert into t_image_upload
  115. (
  116. image_name,
  117. image
  118. )
  119. values
  120. (
  121. '$this->image_name',
  122. '$image'
  123. )";
  124. if(mysql_query($query)){
  125. echo "Insert success";
  126. }
  127. else
  128. {
  129. echo "Insert not success";
  130. }
  131. }
  132.  
  133. function get_all_image_list(){
  134. $query = "select *from t_image_upload";
  135. $result = mysql_query($query);
  136. return $result;
  137. }
  138.  
  139. }
  140. ?>
  141.  
  142. <td style="text-align:center" style="width:50%;><img src="images/<?php echo $data['image']; ?>" width="400px" height="200px"></td>
  143. </tr>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement