<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" href="bootstrap/css/footer.css">
<link rel="stylesheet" href="bootstrap/css/base.css">
<link rel="stylesheet" href="bootstrap/css/skeleton.css">
<link rel="stylesheet" href="bootstrap/css/layout.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link type"text/css" rel="Stylesheet" href="bootstrap/css/bootstrap.css" />
<meta charset="UTF-8">
<title>อัพโหลดรูปภาพ</title>
<script>
    window.onunload = refreshParent;
    function refreshParent() {
        window.opener.location.reload();
    }
</script>
</head>

<body>
<?php
	if(trim($_FILES["filUpload"]["tmp_name"]) != "")
	{
		$images = $_FILES["filUpload"]["tmp_name"];
		$new_images = "Thumbnails_".$_FILES["filUpload"]["name"];
		copy($_FILES["filUpload"]["tmp_name"],"imguser/".$_FILES["filUpload"]["name"]);
		$width=400; //*** Fix Width & Heigh (Autu caculate) ***//
		$size=GetimageSize($images);
		$height=round($width*$size[1]/$size[0]);
		$images_orig = ImageCreateFromJPEG($images);
		$photoX = ImagesX($images_orig);
		$photoY = ImagesY($images_orig);
		$images_fin = ImageCreateTrueColor($width, $height);
		ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
		ImageJPEG($images_fin,"imguser/".$new_images);
		ImageDestroy($images_orig);
		ImageDestroy($images_fin);
		
	$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
	$objDB = mysql_select_db("afm_ass");
		$strSQL = "UPDATE tb_user";
		$strSQL .=" SET Image = '".$new_images."' WHERE User_id = '".$_POST["userid"]."' ";
		$objQuery = mysql_query($strSQL);		

			echo "Copy/Upload Complete<br>";
	}
?>
<input type="button" name="btnClose" class="btn btn-danger" value="Close" OnClick="window.close();">
</body>
</html>
