Samsung SL30 10MP Digital Camera with 3x Optical Zoom and 2.5 inch LCD
Samsung SL30 10MP Digital Camera with 3x Optical Zoom and 2.5 inch LCD
Samsung S5233 with 3 MP Camera, MP3 player
Apple iPod nano 8 GB Mavi
:: HOME PHP Image Resizing & Uploading
Image Resizing & Uploading

To be able to resize image with PHP, You can use below function :

PHP Resize Image function :

     function image_resize($type, $l, $w, $h)
        if($type=="png") header("Content-type: image/png");
        elseif($type=="jpg") header("Content-type: image/jpeg");
        elseif($type=="gif") header("Content-type: image/gif");

        if($type=="png")     $imgs=imagecreatefrompng($l);
        elseif($type=="jpg")     $imgs=imagecreatefromjpeg($l
        elseif($type=="gif")     $imgs=imagecreatefromgif($l

        $sheight = $h;
        $swidth = $w;
        $imgss = ImageCreateTrueColor($swidth,$sheight);


        if($type=="png")     imagepng($imgss,$l);
        elseif($type=="jpg")     imagejpeg($imgss,$l);
        elseif($type=="gif")     imagegif($imgss,$l);


 As you see, we get 4 variables to resize our image. At first we get the type of the image($type), location of image ($l), requested width of image ($w) and requested height of image($h).

PHP file that upload image and run image_resize function :

         upload($_POST['width'], $_POST['height'], $_FILES['img']);

        function upload($h, $w, $photo)


        if($photo['size']>2000000) return false; // put your maximum file size limit
        $i = strlen($photo['name']);
        $type = substr($photo['name'],($i-3),3); // getting image type

        if($type<>"jpg" AND $type<>"gif" AND $type<>"png") return false; // check image type
        $randnum="uploaded"."_".time(); // determine image name
        $loc="images/".$randnum.".".$type.""; // image location on server

        copy($photo['tmp_name'],$loc); // copy image to server

        image_resize($image,$type,$loc,$w,$h); // resizing

        $image = $randnum.".".$type;
            // do whatever you want


HTML file with upload form to upload image :

<form action="upload.PHP" method="post" enctype="multipart/form-data">
<table border="1" cellspacing="0" cellpadding="0" width="100%">
        <td colspan="2">New Image</td>
        <td>Title : </td>
        <td><input type="file" name="img"></td>
        <td>Width : </td>
        <td><input type="text" name="width"></td>
        <td>Height : </td>
        <td><input type="text" name="height"></td>
        <td colspan="2">
            <input type="submit" name="submit" value="UPLOAD">