我有这个脚本用于将图像上传到我的网站但是我希望在上传之前减小文件大小但不减小维度是什么最好的方法呢?我宁愿在上传时这样做,而不是在可能的情况下将其整理出来。
提前致谢
if (isset($_POST['addphotogallery']))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
}
$allowedExts = array("gif", "jpeg", "jpg", "png", "GIF", "JPEG", "JPG", "PNG");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif") ||
($_FILES["file"]["type"] == "image/jpeg") ||
($_FILES["file"]["type"] == "image/jpg") ||
($_FILES["file"]["type"] == "image/pjpeg") ||
($_FILES["file"]["type"] == "image/x-png") ||
($_FILES["file"]["type"] == "image/png")) &&
($_FILES["file"]["size"] < 100000000) &&
in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
if (file_exists("gallery/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "gallery/" . $_FILES["file"]["name"]);
echo "Image Uploaded";
$sql = "INSERT INTO gallery SET filename='".$_FILES["file"]["name"]."' , imagedesc='".$_POST['imgdesc']."' , imagename='".$_POST['imgname']."'";
$res = mysql_query($sql);
}
}
}
else
{
echo "Invalid file";
}
}