日期:2012-11-14  浏览次数:20452 次

<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="486" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="498" height="28" background="image/top.gif"><div align="center" class="style2">上传图片</div></td>
    </tr>
    <tr>
      <td> </td>
    </tr>
    <tr>
      <td><div align="right">
        <table width="426" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="50" height="32" nowrap="nowrap">路径:</td>
            <td width="362"><input name="upfile" type="file" id="upfile" size="40" /></td>
          </tr>
         
          <tr>
            <td height="27" colspan="2"><div align="center">
                <input type="submit" name="Submit" value="提交" />
  
<input type="reset" name="Submit" value="重置" />
</div></td>
          </tr>
        </table>
          </div>
        <div align="center"></div></td>
    </tr>
    <tr>
      <td> </td>
    </tr><INPUT TYPE="hidden" name='action' value='doup'>
    <tr>
      <td height="28" background="image/top.gif"> </td>
    </tr>
    <tr>
      <td> </td>
    </tr>
  </table>
</form>
<br>
<A href=http://www.webjx.com target=_blank>网页教学网webjx.com</A>
<?
if($_POST['action']=='doup')
{
$uptypes=array('image/jpg','image/jpeg','image/pjpeg','image/gif');//上传图片文件类型列表
$wFile=$_FILES['upfile'];//取得文件路径
$waterimg="water.gif";//水印图片路径
//print_r($wFile);
if(in_array($wFile['type'], $uptypes))
{//检查文件类型,若上传的文件为jpg或gif图片则加水印
   if(strstr($wFile['type'],"jp"))
    { //若上传图片类型为jpg,pjpeg,jpeg,则用imagecreatefromjpeg读取目标文件
    $im = imageCreatefromjpeg($wFile['tmp_name']);
$wfilew=imagesx($im);//取得图片的宽
$wfileh=imagesy($im);//取得图片的高
   }
   else
    {//否则若上传图片类型为gif,则用imagecreatefromgif读取目标文件
    $im = imageCreatefromgif($wFile['tmp_name']);
$wfilew=imagesx($im);//取得图片的宽
$wfileh=imagesy($im);//取得图片的高
}
   //设定混合模式
    imagealphablending($im, true);
    //读取水印文件
    $im2 = imagecreatefrompng($waterimg);//若水印图片为jpg,则此去可改为$im2 = imagecreatefromjpeg($waterimg)
 //$white = imagecolorallocate($im2, 255, 255, 255);
  // imagecolortransparent($im2,$white);   //设透明色,这两句可不要
$waterw=imagesx($im2);//取得水印图片的宽