Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- //include("include/session.php");
- //if($session->logged_in){
- $dbhost = 'localhost';
- $dbuser = 'tillis_travel';
- $dbpass = 'parola';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
- $dbname = 'tillis_travel';
- mysql_select_db($dbname);
- //$xuser = $session->username;
- $numestatiune = $_POST['numestatiune'];
- $numehotel = $_POST['numehotel'];
- $stelehotel = $_POST['stelehotel'];
- $durata = $_POST['durata'];
- $descrierehotel = $_POST['descrierehotel'];
- $descrierestatiune = $_POST['descrierestatiune'];
- $titluanunt = $_POST['titluanunt'];
- $transport = $_POST['transport'];
- $perioada = $_POST['perioada'];
- $pret1 = $_POST['pret1'];
- $pret2 = $_POST['pret2'];
- $valuta = $_POST['valuta'];
- $infopret = $_POST['infopret'];
- $pretpersoane = $_POST['pretpersoane'];
- $pretdurata = $_POST['pretdurata'];
- $tipcazare = $_POST['tipcazare'];
- $data = array();
- foreach(array_keys($_POST['field1']) as $n)
- $data[] = $_POST['field1'][$n] . '|' . $_POST['field2'][$n] . '|' . $_POST['field3'][$n];
- $value = mysql_real_escape_string(implode("\n",$data)); //Use a new line...you can always convert it to a BR later with nl2br()
- //mysql_query("INSERT INTO anuntt (perioadax) VALUES ('{$value}')");
- //foreach(array_keys($_POST['field1']) as $n){
- // print $_POST['field1'][$n] . '|' . $_POST['field2'][$n] . '|' . $_POST['field3'][$n] . '<br>';
- $sql=" INSERT INTO anuntt VALUES('$numestatiune','$numehotel','$stelehotel', '$durata', '$descrierehotel', '$descrierestatiune', '$titluanunt', '$transport', '$perioada', '$pret1', '$pret2', '$valuta', '$infopret', '$pretpersoane', '$pretdurata', '$tipcazare', '{$value}')";
- if (!mysql_query($sql,$conn))
- {
- die('Error: ' . mysql_error());
- }
- echo "1 record added";
- $width = '640';
- $height = '640';
- $thumbName = "images/$numestatiune/thumb";
- $twidth = '250';
- $theight = '250';
- if(empty($_POST['numestatiune']))
- {
- die("
- You didn't enter a numestatiune number. Please go back
- ");
- }
- if(file_exists("images/$numestatiune"))
- {
- die("
- You are trying to add a listing that already exists
- ");
- }
- $oldmask = umask(0);
- mkdir("images/$numestatiune", 0777);
- umask($oldmask);
- $ext = '.jpg';
- $fileName = "images/$numestatiune/";
- for($i=0; $i<10; $i++)
- if(!empty($_FILES["upload$i"]['name']))
- {
- $pic[$i] = $_FILES["upload$i"]['name'];
- }
- $totalPics = count($pic);
- for($i = 0; $i<$totalPics; $i++)
- if (!eregi('^image/p?jpeg(;.*)?$', $_FILES["upload$i"]['type']))
- {
- rmdir("images/$numestatiune");
- die("
- Sorry, this was not a .jpg file
- ");
- }
- else
- {
- // your missing a for loop here. Its not looping through all the files. Look at line 166 to see how it should be looping
- if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
- copy($_FILES["upload$i"]['tmp_name'], "$fileName$i$ext"))
- {
- $simg = imagecreatefromjpeg("$fileName" ."$i". "$ext");
- $currwidth = imagesx($simg);
- $currheight = imagesy($simg);
- if($currheight>$currwidth)
- {
- $zoom = $width/$currheight;
- $newheight = $height;
- $newwidth = $currwidth*$zoom;
- }
- else
- {
- $zoom = $width/$currwidth;
- $newwidth = $width;
- $newheight = $currheight*$zoom;
- }
- $dimg = imagecreatetruecolor($newwidth, $newheight);
- $palsize = imagecolorstotal($simg);
- for($e = 0; $e<$palsize; $e++)
- {
- $colors = imagecolorsforindex($simg, $e);
- $imagecolorallocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
- }
- imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
- imagejpeg($dimg, "$fileName" ."$i". "$ext", 90);
- imagedestroy($simg);
- imagedestroy($dimg);
- $newheight = round($newheight);
- $newwidth = round($newwidth);
- $sql2 = "INSERT INTO images SET
- numestatiune='$numestatiune',
- filename='$fileName$i$ext',
- width='$newwidth',
- height='$newheight'
- ";
- if(mysql_query($sql2))
- {
- echo "images uploaded and resized";
- }
- else
- {
- echo "error uploading and resizing images";
- }
- }
- }
- for($i=0; $i<10; $i++)
- if(!empty($_FILES["upload$i"]['name']))
- {
- $pic[$i] = $_FILES["upload$i"]['name'];
- }
- $totalPics = count($pic);
- // see how this whole block is inside a for loop. This block is doing what its suppose to be doing.
- // looping through the total amount of pictures, resizing, renaming and uploading
- for($i = 0; $i<$totalPics; $i++)
- if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
- copy($_FILES["upload$i"]['tmp_name'], "$thumbName$i$ext"))
- {
- $tsimg = imagecreatefromjpeg("$thumbName" ."$i". "$ext");
- $tcurrwidth = imagesx($tsimg);
- $tcurrheight = imagesy($tsimg);
- if($tcurrheight>$tcurrwidth)
- {
- $tzoom = $twidth/$tcurrheight;
- $tnewheight = $theight;
- $tnewwidth = $tcurrwidth*$tzoom;
- }
- else
- {
- $tzoom = $twidth/$tcurrwidth;
- $tnewwidth = $twidth;
- $tnewheight = $tcurrheight*$tzoom;
- }
- $tdimg = imagecreatetruecolor($tnewwidth, $tnewheight);
- $tpalsize = imagecolorstotal($tsimg);
- for($e = 0; $e<$palsize; $e++)
- {
- $colors = imagecolorsforindex($tsimg, $e);
- imagecolorallocate($tdimg, $colors['red'], $colors['green'], $colors['blue']);
- }
- imagecopyresized($tdimg, $tsimg, 0, 0, 0, 0, $tnewwidth, $tnewheight, $tcurrwidth, $tcurrheight);
- imagejpeg($tdimg, "$thumbName" ."$i". "$ext", 90);
- imagedestroy($tsimg);
- imagedestroy($tdimg);
- $tnewheight = round($tnewheight);
- $tnewwidth = round($tnewwidth);
- }
- // now lets add the listing information and thumbnail information to the "listing" table
- $sql3 = "INSERT INTO thumbs SET
- numestatiune='$numestatiune',
- filename='$thumbName$i$ext',
- width='$tnewwidth',
- height='$tnewheight'
- ";
- if(mysql_query($sql3))
- {
- echo "THUMBs stored in database $totalPics";
- }
- else
- {
- echo "Error: Listing did not store in database";
- }
- // now lets add the listing information and thumbnail information to the "listing" table
- mysql_close($conn);
- //}
- ////else{
- //echo "<h1>NOT Logged In</h1>";
- //}
- ?>
Add Comment
Please, Sign In to add comment