Search the Community
Showing results for tags 'uploading images with arrays'.
-
Hi everyone. I'm have a website I took over and I'm looking on the page to upload photos. When you upload a photo you can only choose one from that window and then you have to keep repeating the process if there are more than one image in the file. Could anyone please help me or point me in the right direction. <?php include "../sql.php"; if ($_SESSION['admin'] != 1) { header("Location: /admin"); die(); } $file = $_FILES['Filedata']['name']; $tmpfile = $_FILES['Filedata']['tmp_name']; $name = md5(microtime()); $ext = strtolower(end(split("\.", $file))); if ($ext == "png") $img = imagecreatefrompng($tmpfile) or die("failed"); elseif ($ext == "gif") $img = imagecreatefromgif($tmpfile) or die("failed"); else $img = imagecreatefromjpeg($tmpfile) or die("failed"); $width = imageSX($img); $height = imageSY($img); for ($i = 0; $i <= 1; $i++) { if ($i == 1) { //$target_width = 750; $target_width = 640; $target_height = ceil($target_width * 3/4); } else { $target_width = 105; $target_height = ceil($target_width * 3/4); } if ($width > $target_width || $height > $target_height) { $tr = $target_width/$target_height; $ir = $width/$height; if ($ir > $tr) // too wide $target_height = $target_width / $ir; else // too tall $target_width = $target_height * $ir; } else { $target_width = $width; $target_height = $height; } if ($i == 0) { $car_id = intval($_POST['car_id']); mysql_query("insert into images (car_id) values (" . $car_id . ")"); $img_id = mysql_insert_id(); } $target_dir = "../images/vehicles"; //mkdir($target_dir, 0777, true); $new_img = ImageCreateTrueColor($target_width, $target_height); imagecopyresampled($new_img, $img, 0, 0, 0, 0, $target_width, $target_height, $width, $height); imagejpeg($new_img, $target_dir . "/" . $car_id . "-" . $img_id . ($i == 0 ? "t" : "") . ".jpg", 90); //die($target_dir . "/" . $car_id . "-" . $img_id . ($i == 0 ? "t" : "") . ".jpg"); } unlink($_FILES['Filedata']['tmp_name']); if (end(mysql_fetch_array(mysql_query("select count(*) from images where main=1 and car_id=" . $car_id), MYSQL_ASSOC)) == 0) mysql_query("update images set main=1 where car_id=" . $car_id . " limit 1"); header("Location: carpics.php?id=" . $car_id); ?> Thank you in advance.