0

我是初学者,我一直在尝试减小上传时的图像大小,但没有得到结果。请帮我。 这是我的 PHP 代码

<?php
if (isset($_POST['update'])){
header('Location:index2.php');  
$upload_image = $_FILES["image"][ "name" ];
$folder = "images/";
move_uploaded_file($_FILES["image"]["tmp_name"], "$folder".$_FILES["image"]["name"]);
$file = 'images/'.$_FILES["image"]["name"];
$uploadimage = $folder.$_FILES["image"]["name"];
$newname = $_FILES["image"]["name"];
$random = substr(number_format(time() * rand(),0,'',''),0,10);
$resize_image = $folder.$newname.$random; 
$actual_image = $folder.$newname;

list( $width,$height ) = getimagesize( $uploadimage );

$newwidth = 600;

$newheight = 600;

$thumb = imagecreatetruecolor( $newwidth, $newheight );
$source = imagecreatefromjpeg($actual_image);

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

imagejpeg( $thumb, $resize_image, 60 ); 

$out_image=addslashes(file_get_contents($resize_image));


$userid = $_SESSION['id'];
$date = $_POST['date'];
$data = mysqli_query($db, "SELECT `image` FROM `posts` WHERE id = '$userid' ");
$sql = "insert into posts (userid, image, date) values ('$userid', '$image', '$date')";
mysqli_query($db, $sql);



}

?>

如果我使用此代码,我将旋转图像并且图像也不会减少。

4

0 回答 0