extract($_POST);
$upimage = "upimage/".date("Ym")."/";//上传位置
if(!is_dir($upimage)){
mkdir($upimage); }
$filenum=count($_FILES['file']['tmp_name']);
for($i=0;$i<$filenum;$i++){
$file = "";
if(is_uploaded_file($_FILES['file']['tmp_name'][$i])){//是否用POST上传
if($_FILES['file']['type'][$i] != ("image/jpeg" || "image/pjpeg")){
die(printTop("只能上传jpg图像!")); }
$im = imagecreatefromjpeg($_FILES['file']['tmp_name'][$i]);
$file = $upimage.date("YmdHis").rand(1000,9999);
$w = imagesx($im);
$h = imagesy($im);
if($w > 800 || $h > 800){
ResizeImage($im,800,800,$file.".jpg");
}else{ move_uploaded_file($_FILES['file']['tmp_name'][$i],$file.".jpg");}
//以下为增加行
//设置水印类型 1字符串 2图片 请自行设置
$watertype=1;
//设置水印字符串 请自行设置
$waterstring="MY hand MY mouth";
//设置水印图片名 请自行设置
$waterimage="water.gif";
$destination=$file.".jpg";
$image_size = getimagesize($destination);
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
$white=imagecolorallocate($nimage,255,255,255);
$black=imagecolorallocate($nimage,0,0,0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);
$simage =imagecreatefromjpeg($destination);
imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
imagefilledrectangle($nimage,1,$image_size[1]-15,120,$image_size[1],$white);
switch($watertype)
{
case 1: //加水印字符串
imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
break;
case 2: //加水印图片
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
break;
}
imagejpeg($nimage, $destination);
imagedestroy($nimage);
imagedestroy($simage);
//以上为增加行//
ResizeImage($im,130,130,$file."n.jpg");}
$date = date("Y-m-d H:i:s");
$conn = new db_conn();
$sql = "INSERT INTO product (ptype,title,title_en,image,text,text_en,date) VALUES ($ptype,'$title','$title_en','$file','$text','$text_en','$date')";
$result = $conn->db_query($sql);
if($result){
echo printTop("添加成功!");}else{
echo printTop("添加失败!");}
$conn->db_close();}
}
function types(){?>