Guest User

Untitled

a guest
May 3rd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 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. if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
  107. copy($_FILES["upload$i"]['tmp_name'], "$fileName$i$ext"))
  108. {
  109. $simg = imagecreatefromjpeg("$fileName" ."$i". "$ext");
  110. $currwidth = imagesx($simg);
  111. $currheight = imagesy($simg);
  112. if($currheight>$currwidth)
  113. {
  114. $zoom = $width/$currheight;
  115. $newheight = $height;
  116. $newwidth = $currwidth*$zoom;
  117. }
  118. else
  119. {
  120. $zoom = $width/$currwidth;
  121. $newwidth = $width;
  122. $newheight = $currheight*$zoom;
  123. }
  124.  
  125.  
  126. $dimg = imagecreatetruecolor($newwidth, $newheight);
  127. $palsize = imagecolorstotal($simg);
  128. for($e = 0; $e<$palsize; $e++)
  129. {
  130. $colors = imagecolorsforindex($simg, $e);
  131. $imagecolorallocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
  132. }
  133. imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
  134. imagejpeg($dimg, "$fileName" ."$i". "$ext", 90);
  135. imagedestroy($simg);
  136. imagedestroy($dimg);
  137.  
  138. $newheight = round($newheight);
  139. $newwidth = round($newwidth);
  140.  
  141. $sql2 = "INSERT INTO images SET
  142. numestatiune='$numestatiune',
  143. filename='$fileName$i$ext',
  144. width='$newwidth',
  145. height='$newheight'
  146. ";
  147.  
  148. if(mysql_query($sql2))
  149. {
  150. echo "images uploaded and resized";
  151. }
  152. else
  153. {
  154. echo "error uploading and resizing images";
  155. }
  156. }
  157. }
  158.  
  159. for($i=0; $i<10; $i++)
  160. if(!empty($_FILES["upload$i"]['name']))
  161. {
  162. $pic[$i] = $_FILES["upload$i"]['name'];
  163. }
  164.  
  165. $totalPics = count($pic);
  166.  
  167. for($i = 0; $i<$totalPics; $i++)
  168. if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
  169. copy($_FILES["upload$i"]['tmp_name'], "$thumbName$i$ext"))
  170. {
  171. $tsimg = imagecreatefromjpeg("$thumbName" ."$i". "$ext");
  172. $tcurrwidth = imagesx($tsimg);
  173. $tcurrheight = imagesy($tsimg);
  174. if($tcurrheight>$tcurrwidth)
  175. {
  176. $tzoom = $twidth/$tcurrheight;
  177. $tnewheight = $theight;
  178. $tnewwidth = $tcurrwidth*$tzoom;
  179. }
  180. else
  181. {
  182. $tzoom = $twidth/$tcurrwidth;
  183. $tnewwidth = $twidth;
  184. $tnewheight = $tcurrheight*$tzoom;
  185. }
  186. $tdimg = imagecreatetruecolor($tnewwidth, $tnewheight);
  187. $tpalsize = imagecolorstotal($tsimg);
  188. for($e = 0; $e<$palsize; $e++)
  189. {
  190. $colors = imagecolorsforindex($tsimg, $e);
  191. imagecolorallocate($tdimg, $colors['red'], $colors['green'], $colors['blue']);
  192. }
  193. imagecopyresized($tdimg, $tsimg, 0, 0, 0, 0, $tnewwidth, $tnewheight, $tcurrwidth, $tcurrheight);
  194. imagejpeg($tdimg, "$thumbName" ."$i". "$ext", 90);
  195. imagedestroy($tsimg);
  196. imagedestroy($tdimg);
  197. $tnewheight = round($tnewheight);
  198. $tnewwidth = round($tnewwidth);
  199. }
  200.  
  201. // now lets add the listing information and thumbnail information to the "listing" table
  202. $sql3 = "INSERT INTO thumbs SET
  203. numestatiune='$numestatiune',
  204. filename='$thumbName$i$ext',
  205. width='$tnewwidth',
  206. height='$tnewheight'
  207. ";
  208.  
  209. if(mysql_query($sql3))
  210. {
  211. echo "THUMBs stored in database $totalPics";
  212. }
  213. else
  214. {
  215. echo "Error: Listing did not store in database";
  216. }
  217.  
  218. // now lets add the listing information and thumbnail information to the "listing" table
  219.  
  220.  
  221.  
  222.  
  223. mysql_close($conn);
  224.  
  225. //}
  226. ////else{
  227. //echo "<h1>NOT Logged In</h1>";
  228. //}
  229. ?>
Add Comment
Please, Sign In to add comment