从上传的图像创建缩略图
2022-08-30 12:45:35
我想从用户上传的图像创建缩略图,以便图像看起来不会被挤压。但也想要原始图像的副本。因此,我希望原始图像将原始图像发送到我的服务器,并创建一个拇指版本并将其发送到我的服务器,以便我可以为每个上传自己图像的用户调用每个图像。
我的用户表有 2 个表
`user_pic` longblob NOT NULL,
`user_pic_small` longblob NOT NULL,
我对编码的图像方面并不热衷,但这就是我到目前为止所拥有的。
图像上传.php
> <form id="myForm" action="include/media.profileimage.upload.php"
> method="POST" enctype="multipart/form-data" target="ifr1">
> <input type = "file" name = "image_data" class = "input_text" style="width:800px;" >
> <input type = "submit" name = "submit" class = "btn_login" value = "Upload">
> </form>
media.profileimage.upload.php
if(isset($_FILES['image_data'])){
if(is_uploaded_file($_FILES['image_data']['tmp_name'])) {
// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['image_data']['tmp_name']));
// get the image info..
$size = getimagesize($_FILES['image_data']['tmp_name']);
// our sql query
$creator_id = $_SESSION['id'];
$sql = "UPDATE users SET user_pic='".$imgData."' WHERE id=$creator_id";
$sql2 = "INSERT INTO userphotos(photo_ownerid,photo_ispublic, photo_name, photo_caption, photo_imagedata) VALUES ($creator_id,1,'Profile Picture','Profile Picture','$imgData')";
// insert the image
if(!mysql_query($sql)) {
echo "Fail. It broke.";
}else{
$c=mysql_query($sql2);
echo "<script> parent.alert('Image Uploaded','',1000);</script>";
}
}
}
将不胜感激任何帮助或指导。谢谢