<?php require('system/login.php');  ?>
<?php require_once('../Connections/BE2.php'); ?>
<?php
 
$picpath= "/webpic/"; 
$write='';
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	$tfile="fileToUpload1";
    if ($_FILES[$tfile]["name"]<>'') {
	
	$ext= explode('.',$_FILES[$tfile]['name']) ;
	$imgext=strtolower($ext[count($ext)-1]); //取最後一筆
	$img=date("YmdHis").sprintf("%04d",rand(1,9999)).".".$imgext;	
	//$img=$img.".".$imgext;
    $size= getimagesize($_FILES[$tfile]["tmp_name"]); // 取得圖檔的資訊
	
	
	
	$size= getimagesize($_FILES[$tfile]["tmp_name"]); // 取得圖檔的資訊
    $pic=$wwwpath.$picpath.$img;
	$thumbspic=$wwwpath.$picpath."_thumbs/".$img;
	 
    move_uploaded_file($_FILES[$tfile]["tmp_name"],$pic);
	
	$w=100;
	$h=intval( $size[1]*$w/$size[0]);
    $size2=$w."x".$h;
        // $exec_str="/usr/local/bin/convert -geometry ".$size2." ".$_FILES[$tfile]["tmp_name"]." ".$pic; 
	$exec_str="/usr/local/bin/convert -geometry ".$size2." ".$pic." ".$thumbspic; 
	exec($exec_str);
		 
	$updateSQL = sprintf("INSERT INTO webpic(gdoc,jpg,wsize) VALUES ('%s','%s','%s')",$_POST['gdoc'],$img,$size[0]."X".$size[1]);
    mysql_select_db($database_BE2, $BE2);
    $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());  
    
	$write='資料已更新...';
	$insertGoTo = $_POST['url'];
    // header(sprintf("Location: %s", $insertGoTo)); 
    echo  "<script>alert('".$write."');location.href='".$_POST['url']."';</script>";
	// $write='圖檔'.$_POST['pic_id'].'已更新...';
	 }

  
  

  }


?>




<form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="">
<table border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th width="56" nowrap="nowrap" class="font2" >&nbsp;</th>
    <th width="287" nowrap="nowrap" class="font2" >&nbsp;</th>
    <th width="64" nowrap="nowrap" class="font2" >&nbsp;</th>
    </tr>
  <tr>
    <th nowrap="nowrap">&nbsp;</th>
    <th nowrap="nowrap">圖片說明</th>
    <th nowrap="nowrap">&nbsp;</th>
    </tr>
 
    <tr >
      <td height="32">&nbsp;</td>
      <td><input name="gdoc" type="text" id="gdoc" value="" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="fileToUpload1" type="file" id="fileToUpload1" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="送出" />
      <input name="url" type="hidden" id="url" value="<? echo $_SERVER['HTTP_REFERER']; ?>" /></td>
    <td>&nbsp;</td>
    </tr>
</table> 

<input name="MM_insert" type="hidden" id="MM_insert" value="form1">
</form>

