源代码:<?php
/*
 * Created on 2011-9-10
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
//error_reporting(0); //==========================文件上传================================
 function upLoad(){
   $upFile=$_FILES["upFile"];
   $name=$upFile["name"];
   $type=$upFile["type"];
   $tmp_name=$upFile["tmp_name"];
   $error=$upFile["error"];
   $size=$upFile["size"];   //判断只能上传指定格式的图片
   switch($type)
   {
    case "image/pjpeg": $img_ok=1;break;
    case "image/bmp": $img_ok=1;break;
    case "image/gif": $img_ok=1;break;
    case "image/png": $img_ok=1;break;
   }   //将文件移到服务器指定文件夹
   if($img_ok){
    move_uploaded_file($tmp_name,$name);
    echo "<script>alert('上传成功!')</script>";
   }else{
    echo "<script>alert('上传的不是指定类型的图片,上传失败!')</script>";
   }
   return $name;
 }
//============================神奇的分割线=============================================
//============================水印的添加===============================================//==========图像的解析编码=====================function encode($num,$image){
switch($num)
{
case 1:$im=@ImageCreateFromGIF($image);break;
case 2:$im=@ImageCreateFromJPEG($image);break;
case 3:$im=@ImageCreateFromPNG($image);break;
}
return $im;}//===============小小的分割线=======================function addWaterMark(){
$image=upLoad();
if($image){
$img=getimagesize($image);//$img[2]的值意义:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP
$im=encode($img[2],$image); $fontcol=imagecolorallocate($im,255,255,255);
$str=iconv("gbk","utf-8","最最最最最最子最最最最");
imagettftext($im,12,0,20,20,$fontcol,"simhei.ttf",$str);
header("Content-type:image/jpeg");
imagejpeg($im);
}
}
//==================================================================================
addWaterMark();
?>
  <form action="" method="post" enctype="multipart/form-data" name="upForm">
  <p>图像的上传:</p>
  <input type="file" name="upFile" size="50" maxlength="100000" /><br/>
  <input type="submit" value="上传"/><br />
  </form>