我正在制作一个图像压缩工具来压缩图像大小
为此,我制作了下面给出的代码
<?php
$name = '';
$type = '';
$size = '';
$error = '';
function compress_image($source_url, $destination_url, $quality)
{
$info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($source_url);
imagejpeg($image, $destination_url, $quality);
} elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source_url);
imagegif($image, $destination_url, $quality);
} elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source_url);
imagepng($image, $destination_url, 5);
}
return $destination_url;
}
if ($_FILES["file"]["error"] > 0) {
$error = $_FILES["file"]["error"];
} else if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) {
$url = $_FILES["file"]["name"];
$temp_file = $_FILES["file"]["tmp_name"];
$filename = compress_image($temp_file, $url, 80);
rename($filename, 'https://example.com/wp-content/themes/twentytwenty/templates/images/' . $filename);
$location = "https://example.com/wp-content/themes/twentytwenty/templates/images/" . $url;
/*$image_size = getimagesize($location);*/
echo 'https://example.com/wp-content/themes/twentytwenty/templates/images/' . $filename; die();
} else {
$error = "Uploaded image should be jpg or gif or png";
}
但是我的文件问题不能在它创建的图像文件夹中https://example.com/wp-content/themes/twentytwenty/templates/移动
我不知道为什么这是一个问题
谁能帮我解决这个问题
UYOU