array_slice 从数组中取出一段
sort 对数组排序
array_unique 移除数组中重复的值
应你的要求,修改了。我测试了一下,是可以的,你自己测试一下。<?php } function news(){?>
<form action="?type=productNews" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr><tr><td height="30"><label>名称A:
<input name="title" type="text" id="title" size="30" />
</label></td></tr><tr><td height="30"><label>名称B:
<input name="title_en" type="text" id="title_en" size="30" />
</label></td></tr><tr><td height="30"><label>分类:
<select name="ptype" id="ptype">
<?php $conn = new db_conn()
$sql = "SELECT * FROM product_type"
$result = $conn->db_query($sql)
while($rows=mysql_fetch_assoc($result)){?>
<option value="<?php echo $rows['id']?>"><?php echo $rows['name']." / ".$rows['name_en']?></option>
<?php } $conn->db_close()?>
</select>
</label></td></tr><tr><td height="30"><label>图片:
<input name="file" type="file" id="file" size="50" />
</label></td></tr><tr><td>说明A:
<input name="text" type="text" id="text" size="30" /></td>
</tr><tr><td>说明B:
<input name="en_text" type="text" id="en_text" size="30" /></td>
</tr><tr><td align="center"><label>
<input type="submit" name="button" id="button" value="提交" />
</label></td></tr><tr><td></td></tr></table></form>
<?php }function productNews(){
extract($_POST)
$upimage = "upimage/".date("Ym")."/"//上传位置
if(!is_dir($upimage)){
mkdir($upimage)}
$file = ""
if(is_uploaded_file($_FILES['file']['tmp_name'])){//是否用POST上传
if($_FILES['file']['type'] != ("image/jpeg" || "image/pjpeg")){
die(printTop("只能上传jpg图像!"))}
$im = imagecreatefromjpeg($_FILES['file']['tmp_name'])
$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'],$file.".jpg")}
//以下为增加行
$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(){?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)