0

How can i add image converter for this upload function? I would like always save image with JPG format.

This is my PHP code :

    foreach($_FILES["thpostimg"]["error"] as $key => $value) {
      if($_FILES["thpostimg"]["tmp_name"][$key] == NULL)
                  { $thpostimg = $_FILES["thpostimg"]["name"][$key]; } else 
                   { 
                   $ext = strtolower(pathinfo($_FILES["thpostimg"]["name"][$key], PATHINFO_EXTENSION));
                   $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                   $rand_dir_name = substr(str_shuffle($chars), 0, 30);
                   $path = uniqid().'-'.$rand_dir_name.'.' .$ext;
                   $thpostimg = $path;
                   }
     if($_FILES["thpostimg"]["tmp_name"][$key] == NULL){  } else 
             { 
            $arr_image_details = getimagesize($_FILES["thpostimg"]["tmp_name"][$key]); 
            $width = $arr_image_details[0];
            $height = $arr_image_details[1];
            $mime = $arr_image_details['mime'];
             copy($_FILES['thpostimg']['tmp_name'][$key], './upload/'.$thpostimg);
             }
          }
rami-yrm
  • 57
  • 1
  • 11
  • I recommend using http://wideimage.sourceforge.net/ - it allows you to auto-crop as well as save in JPG, PNG, etc. – rybo111 Mar 25 '14 at 12:45
  • PHP has so many built-in image manipulation functions I'm shocked, *shocked* you didn't find them in the extensive googling you no doubt did... http://us1.php.net/manual/en/function.imagejpeg.php – Digital Chris Mar 25 '14 at 12:52
  • 2
    check here http://stackoverflow.com/questions/14550299/how-to-convert-uploaded-images-always-into-jpg-format – Nazaret2005 Mar 25 '14 at 13:25

0 Answers0