我正在制作一个图像压缩工具来压缩图像大小为此,我制作了下面给出的代码<?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/移动我不知道为什么这是一个问题谁能帮我解决这个问题
1 回答
UYOU
TA贡献1878条经验 获得超4个赞
您必须在 中使用本地路径名rename()
,而不是 URL。您可以使用它$_SERVER['DOCUMENT_ROOT']
来获取您网站的根目录。
rename($filename, $_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/twentytwenty/templates/images/' . $filename);
- 1 回答
- 0 关注
- 85 浏览
添加回答
举报
0/150
提交
取消