 <?php
include("mysqlconnect.php");
    function GetImageExtension($imagetype)
   	 {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }

function resize($img){
        /*
        only if you script on another folder get the file name
        */
        //new folder
        $r =explode("/",$img);
        $name=end($r);
        $vdir_upload = "galleryimages/";
        list($width_orig, $height_orig) = getimagesize($img);
        //ne size
        $dst_width = 1000;
        $dst_height = ($dst_width/$width_orig)*$height_orig;
        $im = imagecreatetruecolor($dst_width,$dst_height);
        $image = imagecreatefromjpeg($img);
        imagecopyresampled($im, $image, 0, 0, 0, 0, $dst_width, $dst_height, $width_orig, $height_orig);
        //modive the name as u need
        imagejpeg($im,$vdir_upload . $name);
        //save memory
        imagedestroy($im);
}

if (!empty($_FILES["uploadedimage"]["name"])) {

	$file_name           =   $_FILES["uploadedimage"]["name"];
	$temp_name           =   $_FILES["uploadedimage"]["tmp_name"];
        $imageSize           =   filesize($temp_name);
        if($imageSize>1048576){
            echo "<script> location.href='https://ziabuilders.in/list.php?e=e'; </script>";
            exit;
        }
	$imgtype             =   $_FILES["uploadedimage"]["type"];
	$ext                 =   GetImageExtension($imgtype);
	$imagename           =   date("d-m-Y")."-".time().$ext;
	$target_path         =   "galleryimages/".$imagename;
        $imageUpload         =   move_uploaded_file($temp_name, $target_path);
        
        resize($target_path);
	
        if($imageUpload==1 && $imageUpload==1) {
                $query_upload="INSERT into `images_tbl` (`images_path`,`submission_date`) VALUES 

        ('".$target_path."','".date("Y-m-d")."')";
                mysqli_query($db,$query_upload); 
                echo "<script> location.href='https://ziabuilders.in/list.php?m=s'; </script>";
                exit;

        }else{
           exit("Error While uploading image on the server");
        } 

}

?>;

