php在上传过程中调整图片大小

时间:2013-11-04 14:09:15

标签: php

我知道这个问题是在 here 之前提出的,但我真的需要一些人来解释我如何在我的情况下使用它。

这是我上传图片的简单php脚本:

<?php
    if(isset($_POST['submit'])){
        $ipad=$_SERVER['REMOTE_ADDR'];
        //This is the directory where images will be saved 
        $target = "images/"; 
        $email=$_POST['email'];
        $target = $target . basename( $_FILES['photo']['name']);  
        //This gets all the other information from the form 
        $pic=($_FILES['photo']['name']); 
        $resultes =mysql_query("SELECT * FROM image WHERE `name` = '$pic'");

        if($pic != '' and $email != '' and mysql_num_rows($resultes) == 0){
            mysql_query("INSERT into image(name , email, ipadd) values ('$pic','$email','$ipad' )"); 
            //Writes the photo to the server 
            if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { 
?> 
                <div class="error">The file has been uploaded, and your information has been added to the directory</div>
<? }
        } else { 
        //Gives and error if its not 
        echo '<div class="error">'. $gal_error_noupload .'</div>'; 
        } 
        $pic=='';
    }           

?>

如何添加调整大小代码?这是here

1 个答案:

答案 0 :(得分:0)

<?php
    if(isset($_POST['submit'])){
        $ipad=$_SERVER['REMOTE_ADDR'];
        //This is the directory where images will be saved 
        $target = "images/"; 
        $email=$_POST['email'];
        $target = $target . basename( $_FILES['photo']['name']);  
        //This gets all the other information from the form 
        $pic=($_FILES['photo']['name']); 
        $resultes =mysql_query("SELECT * FROM image WHERE `name` = '$pic'");

        if($pic != '' and $email != '' and mysql_num_rows($resultes) == 0){
            mysql_query("INSERT into image(name , email, ipadd) values ('$pic','$email','$ipad' )"); 
            //Writes the photo to the server 
            if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { 

                            // *** Include the class
                            include("resize-class.php");

                            // *** 1) Initialise / load image
                            $resizeObj = new resize($target);

                            // *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
                            $resizeObj -> resizeImage(200, 200, 'crop');

                            // *** 3) Save image
                            $resizeObj -> saveImage($target, 1000);
                            <div class="error">The file has been uploaded, and your information has been added to the directory</div>

            } else { 
            //Gives and error if its not 
            echo '<div class="error">'. $gal_error_noupload .'</div>'; 
            } 
            $pic=='';
        }
    }           

?>

这应该用较小的版本替换图像。取代

$resizeObj -> saveImage($target, 1000);

如果你想留下一个大的东西,还有别的东西。