0

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

Community
  • 1
  • 1
AndrewS
  • 1,555
  • 4
  • 20
  • 32
  • possible duplicate of [php resize image on or before upload](http://stackoverflow.com/questions/12757005/php-resize-image-on-or-before-upload) – andrewsi Nov 05 '13 at 04:24

1 Answers1

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

?>

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.

Christine
  • 125
  • 8