���� ������������������������������������ $name) { $caption = $captions[$key]; $pins = json_encode(json_decode($pinsArray[$key], true)); $id = $ids[$key]; $imageOrder = $imageOrders[$key]; list($width, $height,$type) = explode(',', $imageSizes[$key]); // Split width and height if (!empty($_FILES['images']['name'][$key])) { $timestamp = time(); $fileExtension = strtolower(pathinfo($name, PATHINFO_EXTENSION)); $nameWithoutSpaces = str_replace(' ', '_', $name); $newFileName = $timestamp . rand(1000, 10000000) . "_" . basename($nameWithoutSpaces); $targetFile = $targetDir . $newFileName; $check = getimagesize($_FILES["images"]["tmp_name"][$key]); if ($check !== false) { if (move_uploaded_file($_FILES["images"]["tmp_name"][$key], $targetFile)) { try { $image = new ImageResize($targetFile); if (!empty($width) && !empty($height)) { if($type=='width'){ $image->resizeToWidth($width); }elseif($type=='height'){ $image->resizeToHeight($height); }elseif ($type=='crop'){ $image->crop($width, $height); }elseif ($type=='widthCrop'){ $image->resizeToWidth($width); $image->crop($width, $height,0, 0); }elseif ($type=='heightCrop'){ $image->resizeToHeight($height); $image->crop($width, $height); }else{ $image->resize($width, $height); } } $image->save($targetFile); $imagePath = $targetFile; } catch (Exception $e) { echo "1- Error resizing image: " . $e->getMessage(); continue; } } else { echo "2 -Error uploading file."; continue; } } else { echo "3 - File is not an image."; continue; } } $query = "INSERT INTO images (image, caption, pins, pid, image_order) VALUES (?, ?, ?, ?, ?)"; $stmt = $conn->prepare($query); $stmt->bind_param("sssii", $imagePath, $caption, $pins, $pid, $imageOrder); if ($stmt->execute()) { echo "Image saved/updated successfully!"; } else { echo "4- Error: " . $stmt->error; } } } ?>