<?
$model=$_POST["model"];
$type=$_POST["REGION1"];
$groups=$_POST["STATE1"];
$name=$_POST["name"];
$weight=$_POST["weight"];
$amount=$_POST["amount"];
$level=$_POST["level"];

$user="cp037684_tbadm";
$password="siamnovaTho1220!";
$database="cp037684_tbadm";
$c = mysql_connect("localhost",$user,$password);

mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=''tis620''");
mysql_query("SET character_set_connection=''tis620''");
mysql_query("collation_connection = tis620_thai_ci");
mysql_query("collation_database = tis620_thai_ci");
mysql_query("collation_server = tis620_thai_ci");
 
@mysql_select_db($database) or die( "Unable to select database");
mysql_db_query($database,"SET NAMES tis620");// 

$q="INSERT INTO product ( type , groups , model , weight , amount , level , timerec , name ) VALUES 
             ('". $type ."', '". $groups ."', '". $model ."', '". $weight ."', '". $amount ."', '". $level ."',". 0 .", '". $name ."')";

if (!$RES = mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
$idpro = mysql_insert_id($c);

if (isset($HTTP_POST_FILES["file1"])) {
$SrcPathFile = $HTTP_POST_FILES["file1"]["tmp_name"];
$SrcFileType = $HTTP_POST_FILES["file1"]["type"];
$DstFileName = $HTTP_POST_FILES["file1"]["name"];

//echo ">$DstFileName";

clearstatcache();
$time = filemtime($SrcPathFile);
$storedate = date("Y-m-d H:i:s", $time);
if (file_exists($SrcPathFile)) {
$q = "insert into file (id,datatype, name, size, filedate) values ('";
$q .= $idpro . "', '" . $SrcFileType . "', '" . $DstFileName . "', " . filesize($SrcPathFile);
$q .= ", '" . $storedate . "')";
if (!$RES = mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
$fileid = mysql_insert_id($c);
$fp = fopen($SrcPathFile, "rb");
while (!feof($fp)) {
  $binarydata = addslashes(fread($fp, 65535));
  $q = "insert into filedata (masterid, filedata) values (";
  $q .= $fileid . ", '" . $binarydata . "')";
  if (!mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
}
fclose($fp);
echo "Upload Complete<br>";
} }
			 
?>
