【问题标题】:Compress image on upload php在上传php时压缩图像
【发布时间】:2015-09-04 20:51:20
【问题描述】:

我正在尝试添加一个功能以在上传图像时减小文件大小,我有上传图像的代码,它工作正常,但对这一切都是新手。我会为此使用 imagejpeg 还是有更好(更简单)的方式?我没有包括我的尝试,因为它们失败了,所以这里是使用基本提交文件输入的工作标准上传脚本..

$file_formats = array("jpg","jpeg","JPEG",'PNG', "png", "gif", "bmp");

$filepath = "upload_images/";


if ($_POST['submitbtn']=="Submit") {
 $name = $_FILES['imagefile']['name'];
 $size = $_FILES['imagefile']['size'];
if (strlen($name)) {
$extension = substr($name, strrpos($name, '.')+1);
if (in_array($extension, $file_formats)) { 
    if ($size < (2048 * 1024)) { 
        $imagename = md5(uniqid() . time()) . "." . $extension;
        $tmp = $_FILES['imagefile']['tmp_name'];


            if (move_uploaded_file($tmp, $filepath . $imagename)) {

                //execute function once uploaded

            } else {
                echo "Could not move the file.";
            }
    } else {
        echo "Your image size is bigger than 2MB.";
    }
} else {
        echo "Invalid file format.";
}
} else {
        echo "Please select image..!";
}

}

【问题讨论】:

标签: php image upload reduce image-size


【解决方案1】:

好的,所以我找到了我的解决方案,而且它非常简单..

http://www.nimrodstech.com/php-image-resize/

我使用上面发布的现有上传代码,并在上传后使用此插件减小大小.. +1 mate!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    相关资源
    最近更新 更多