Guest User

Untitled

a guest
May 3rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. <?
  2. //include("include/session.php");
  3.  
  4. //if($session->logged_in){
  5. $dbhost = 'localhost';
  6. $dbuser = 'tillis_travel';
  7. $dbpass = 'parola';
  8.  
  9. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
  10.  
  11. $dbname = 'tillis_travel';
  12. mysql_select_db($dbname);
  13.  
  14. //$xuser = $session->username;
  15. $numestatiune = $_POST['numestatiune'];
  16. $numehotel = $_POST['numehotel'];
  17. $stelehotel = $_POST['stelehotel'];
  18. $durata = $_POST['durata'];
  19. $descrierehotel = $_POST['descrierehotel'];
  20. $descrierestatiune = $_POST['descrierestatiune'];
  21. $titluanunt = $_POST['titluanunt'];
  22. $transport = $_POST['transport'];
  23. $perioada = $_POST['perioada'];
  24. $pret1 = $_POST['pret1'];
  25. $pret2 = $_POST['pret2'];
  26. $valuta = $_POST['valuta'];
  27. $infopret = $_POST['infopret'];
  28. $pretpersoane = $_POST['pretpersoane'];
  29. $pretdurata = $_POST['pretdurata'];
  30. $tipcazare = $_POST['tipcazare'];
  31. $data = array();
  32. foreach(array_keys($_POST['field1']) as $n)
  33. $data[] = $_POST['field1'][$n] . '|' . $_POST['field2'][$n] . '|' . $_POST['field3'][$n];
  34. $value = mysql_real_escape_string(implode("\n",$data)); //Use a new line...you can always convert it to a BR later with nl2br()
  35. //mysql_query("INSERT INTO anuntt (perioadax) VALUES ('{$value}')");
  36.  
  37. //foreach(array_keys($_POST['field1']) as $n){
  38. // print $_POST['field1'][$n] . '|' . $_POST['field2'][$n] . '|' . $_POST['field3'][$n] . '<br>';
  39.  
  40. $sql=" INSERT INTO anuntt VALUES('$numestatiune','$numehotel','$stelehotel', '$durata', '$descrierehotel', '$descrierestatiune', '$titluanunt', '$transport', '$perioada', '$pret1', '$pret2', '$valuta', '$infopret', '$pretpersoane', '$pretdurata', '$tipcazare', '{$value}')";
  41.  
  42. if (!mysql_query($sql,$conn))
  43. {
  44. die('Error: ' . mysql_error());
  45. }
  46. echo "1 record added";
  47.  
  48. $width = '640';
  49. $height = '640';
  50.  
  51. $thumbName = "images/$numestatiune/thumb";
  52.  
  53. $twidth = '250';
  54. $theight = '250';
  55.  
  56.  
  57. if(empty($_POST['numestatiune']))
  58. {
  59. die("
  60.  
  61. You didn't enter a numestatiune number. Please go back
  62.  
  63. ");
  64. }
  65.  
  66.  
  67. if(file_exists("images/$numestatiune"))
  68. {
  69. die("
  70.  
  71. You are trying to add a listing that already exists
  72.  
  73. ");
  74. }
  75.  
  76.  
  77. $oldmask = umask(0);
  78. mkdir("images/$numestatiune", 0777);
  79. umask($oldmask);
  80. $ext = '.jpg';
  81. $fileName = "images/$numestatiune/";
  82.  
  83.  
  84. for($i=0; $i<10; $i++)
  85. if(!empty($_FILES["upload$i"]['name']))
  86. {
  87. $pic[$i] = $_FILES["upload$i"]['name'];
  88. }
  89.  
  90. $totalPics = count($pic);
  91.  
  92. for($i = 0; $i<$totalPics; $i++)
  93.  
  94. if (!eregi('^image/p?jpeg(;.*)?$', $_FILES["upload$i"]['type']))
  95. {
  96.  
  97. rmdir("images/$numestatiune");
  98. die("
  99.  
  100. Sorry, this was not a .jpg file
  101.  
  102. ");
  103. }
  104. else
  105. {
  106. // your missing a for loop here. Its not looping through all the files. Look at line 166 to see how it should be looping
  107. if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
  108. copy($_FILES["upload$i"]['tmp_name'], "$fileName$i$ext"))
  109. {
  110. $simg = imagecreatefromjpeg("$fileName" ."$i". "$ext");
  111. $currwidth = imagesx($simg);
  112. $currheight = imagesy($simg);
  113. if($currheight>$currwidth)
  114. {
  115. $zoom = $width/$currheight;
  116. $newheight = $height;
  117. $newwidth = $currwidth*$zoom;
  118. }
  119. else
  120. {
  121. $zoom = $width/$currwidth;
  122. $newwidth = $width;
  123. $newheight = $currheight*$zoom;
  124. }
  125.  
  126.  
  127. $dimg = imagecreatetruecolor($newwidth, $newheight);
  128. $palsize = imagecolorstotal($simg);
  129. for($e = 0; $e<$palsize; $e++)
  130. {
  131. $colors = imagecolorsforindex($simg, $e);
  132. $imagecolorallocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
  133. }
  134. imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
  135. imagejpeg($dimg, "$fileName" ."$i". "$ext", 90);
  136. imagedestroy($simg);
  137. imagedestroy($dimg);
  138.  
  139. $newheight = round($newheight);
  140. $newwidth = round($newwidth);
  141.  
  142. $sql2 = "INSERT INTO images SET
  143. numestatiune='$numestatiune',
  144. filename='$fileName$i$ext',
  145. width='$newwidth',
  146. height='$newheight'
  147. ";
  148.  
  149. if(mysql_query($sql2))
  150. {
  151. echo "images uploaded and resized";
  152. }
  153. else
  154. {
  155. echo "error uploading and resizing images";
  156. }
  157. }
  158. }
  159.  
  160. for($i=0; $i<10; $i++)
  161. if(!empty($_FILES["upload$i"]['name']))
  162. {
  163. $pic[$i] = $_FILES["upload$i"]['name'];
  164. }
  165.  
  166. $totalPics = count($pic);
  167.  
  168. // see how this whole block is inside a for loop. This block is doing what its suppose to be doing.
  169. // looping through the total amount of pictures, resizing, renaming and uploading
  170.  
  171. for($i = 0; $i<$totalPics; $i++)
  172. if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
  173. copy($_FILES["upload$i"]['tmp_name'], "$thumbName$i$ext"))
  174. {
  175. $tsimg = imagecreatefromjpeg("$thumbName" ."$i". "$ext");
  176. $tcurrwidth = imagesx($tsimg);
  177. $tcurrheight = imagesy($tsimg);
  178. if($tcurrheight>$tcurrwidth)
  179. {
  180. $tzoom = $twidth/$tcurrheight;
  181. $tnewheight = $theight;
  182. $tnewwidth = $tcurrwidth*$tzoom;
  183. }
  184. else
  185. {
  186. $tzoom = $twidth/$tcurrwidth;
  187. $tnewwidth = $twidth;
  188. $tnewheight = $tcurrheight*$tzoom;
  189. }
  190. $tdimg = imagecreatetruecolor($tnewwidth, $tnewheight);
  191. $tpalsize = imagecolorstotal($tsimg);
  192. for($e = 0; $e<$palsize; $e++)
  193. {
  194. $colors = imagecolorsforindex($tsimg, $e);
  195. imagecolorallocate($tdimg, $colors['red'], $colors['green'], $colors['blue']);
  196. }
  197. imagecopyresized($tdimg, $tsimg, 0, 0, 0, 0, $tnewwidth, $tnewheight, $tcurrwidth, $tcurrheight);
  198. imagejpeg($tdimg, "$thumbName" ."$i". "$ext", 90);
  199. imagedestroy($tsimg);
  200. imagedestroy($tdimg);
  201. $tnewheight = round($tnewheight);
  202. $tnewwidth = round($tnewwidth);
  203. }
  204.  
  205. // now lets add the listing information and thumbnail information to the "listing" table
  206. $sql3 = "INSERT INTO thumbs SET
  207. numestatiune='$numestatiune',
  208. filename='$thumbName$i$ext',
  209. width='$tnewwidth',
  210. height='$tnewheight'
  211. ";
  212.  
  213. if(mysql_query($sql3))
  214. {
  215. echo "THUMBs stored in database $totalPics";
  216. }
  217. else
  218. {
  219. echo "Error: Listing did not store in database";
  220. }
  221.  
  222. // now lets add the listing information and thumbnail information to the "listing" table
  223.  
  224.  
  225.  
  226.  
  227. mysql_close($conn);
  228.  
  229. //}
  230. ////else{
  231. //echo "<h1>NOT Logged In</h1>";
  232. //}
  233. ?>
Add Comment
Please, Sign In to add comment