上传时调整图像大小 [英] Resize an image whilst uploading
本文介绍了上传时调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在用户上传个人资料照片时自动调整图片大小。这是图片上传PHP
I want to resize an image automatically when a user upload a profile picture. This is the image upload PHP
<?php
$user=$_SESSION['dbUser']['username'];
$db=new mysqli('host','username','password','database');
if($db->connect_errno){
echo $db->connect_error;}
$pull="select * from users where user='$user'";
$allowedExts = array("jpg", "jpeg", "gif", "png","JPG","PNG");
$extension = @end(explode(".", $_FILES["file"]["name"]));
if(isset($_POST['pupload'])){
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/PNG"))
&& ($_FILES["file"]["size"] < 200000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Uploaded Successully<br>";
echo "It may take up to half an hour to update.<br><br>";
if (file_exists("upload/" . $_SESSION['dbUser']['username']))
{
unlink("upload/" . $_SESSION['dbUser']['username'].".".$ext);
}
else
{
$pic=$_FILES["file"]["name"];
$conv=explode(".",$pic);
$ext=$conv['1'];
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_SESSION['dbUser']['username'].".jpg");
$url=$user.".jpg";
$query="update picture set url='$url', lastUpload=now() where user='$user'";
if($upl=$db->query($query)){
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
}
}
}
else
{
echo "File Size Limit Crossed 200 KB Use Picture Size less than 200 KB";
}
}
?>
推荐答案
user =
_SESSION [' dbUser '] [' username'];
_SESSION['dbUser']['username'];
db = new mysqli(' host',' 用户名',' password',' database');
if(
db=new mysqli('host','username','password','database'); if(
这篇关于上传时调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文