-1

I need help.

I dont know how to make image resize for all images when multiuploading.

I need to set for all images max. width 1024px equally with height.

<?php
if(isset($_FILES['files'])){
    $errors= array();
    foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
        $file_name = $key.$_FILES['files']['name'][$key];
        $file_size =$_FILES['files']['size'][$key];
        $file_tmp =$_FILES['files']['tmp_name'][$key];
        $file_type=$_FILES['files']['type'][$key];
    $vozidlo='99';  
        if($file_size > 2097152){
            $errors[]='File size must be less than 2 MB';
        }       
        $query="INSERT into vozidla_obrazky (vozidlo, obrazek) VALUES ('$vozidlo','$file_name'); ";
        $desired_dir="../../images/cars";
        if(empty($errors)==true){
            if(is_dir($desired_dir)==false){
                mkdir("$desired_dir", 0700);        // Create directory if it does not exist
            }
            if(is_dir("$desired_dir/".$file_name)==false){
                move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
            }else{                                  // rename the file if another one exist
                $new_dir="$desired_dir/".$file_name.time();
                 rename($file_tmp,$new_dir) ;               
            }
         mysqli_query($db,$query);          
        }else{
                print_r($errors);
        }
    }
    if(empty($error)){
        echo "Success";
    }
}
?>
  • 3
    Have you done any research into how to resize an image in PHP? There's loads of questions on here about it - https://stackoverflow.com/questions/14649645/resize-image-in-php – Andy Holmes Jan 23 '18 at 14:47
  • 4
    Possible duplicate of [Resize image in PHP](https://stackoverflow.com/questions/14649645/resize-image-in-php) – Eddie Jan 23 '18 at 14:51
  • I know, but I am novice in PHP and some one using some frameworks, and I need to know how to write resize to this code, multiple images upload, for better understand resize function. – Martin Zámečník Jan 23 '18 at 17:41
  • Then search for it, there are loads, including the one that I linked you. Google is full of tutorials. It doesn't matter how many images are uploading, you're likely only going to have one method that runs the saving of the file, put the resize in there and it's called for every image. – Andy Holmes Jan 23 '18 at 21:56

1 Answers1

0

This is example of my ooooold code. I was using a double loop for resize and crop image for google maps tiles.

  for ($i = 0; $i < $counter; $i++) {
            for ($j = 0; $j < $counter; $j++) {
                $image->resize(256 * $counter, 256 * $counter);
            }}