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);
}
}