doufang1954 2013-11-04 14:09
浏览 52

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

I know this question was asked before here, but i really need some one to explain me how can i use this in my situation.

This is my simple php script tha uploads the image:

<?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=='';
    }           

?>

How can I add the resize code? That is give here

  • 写回答

1条回答 默认 最新

  • 普通网友 2013-11-05 12:47
    关注
    <?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=='';
            }
        }           
    
    ?>
    

    This should replace the image with the smaller version. Replace

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

    with something else if you want to keep the big one.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100