如何压缩每个图像文件的文件大小并使用foreach
移动到文件夹。如何在php中使用gd扩展来实现这一点?
这是我的代码:
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);
}