How can i compress the file size of each image file and move to folder using foreach. How can I achieve this with gd extension in php?
This is my code:
if($_POST['image_form_submit'] == 1) {
    $galleryGroup = filter_var($_POST['galleryGroup'], FILTER_SANITIZE_NUMBER_INT);
    $images_arr = array();
    foreach ($_FILES['images']['name'] as $key => $val)
    {
        $image_name = $_FILES['images']['name'][$key];
        $tmp_name   = $_FILES['images']['tmp_name'][$key];
        $size       = $_FILES['images']['size'][$key];
        $type       = $_FILES['images']['type'][$key];
        $error       = $_FILES['images']['error'][$key];
        //Upload Temporary Directory
        $target_dir = "../uploads/gallery/";
        $target_file = $target_dir . $_FILES['images']['name'][$key];
        if (move_uploaded_file($_FILES['images']['tmp_name'][$key], $target_file))
        {
            $images_arr[] = $target_file;
        }
        $sqlMaxSO = "SELECT MAX(so) as maxSO FROM gallery_listing";
        $Maxres = mysqli_query($con, $sqlMaxSO);
        $row = mysqli_fetch_assoc($Maxres);
        $maxSO = $row['maxSO'];
        $sql = "INSERT INTO gallery_listing (idGroup, imgImage, so, active) VALUES (" . $galleryGroup . " , '" .  $image_name. "', '" . $maxSO . "', 1);";
        $res = mysqli_query($con, $sql);
    }
 
    