请教关于上传图片

请教关于上传图片

请问,我要限制上传图片的大小,写了下面的代码,但是有问题,好象不能限制.麻烦大家帮我看一下怎么回事.谢谢!
FORM里有:
<input type="hidden" name="max_file_size" id="max_file_size" value="20000"/>
<input name="plant_picture" type="file" id="plant_picture" size="40" />
PHP代码:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_record_page")) {
  // move upload picture file to path image
  $uploadfile = 'images/' . $_FILES['plant_picture']['name'];
  $fileSize = $_FILES['plant_picture']['size'];
  $fileType = $_FILES['plant_picture']['type'];
if (is_uploaded_file($_FILES['plant_picture']['tmp_name']))
  {
          if($fileSize<$_POST['max_file_size'])
          {
          if (!move_uploaded_file($_FILES['plant_picture']['tmp_name'], $uploadfile))
                  {
          echo "<script>alert('Can not upload files.');</script>";
          echo "<script>history.back(-1);</script>";
          exit();
          }
              else
              {
          echo "<script>alert('Can not upload files.');</script>";
          echo "<script>history.back(-1);</script>";
          exit();
          }
          }
        else
        {
    echo "<script>alert('The size of the file is too big.');</script>";
    echo "<script>history.back(-1);</script>";
    exit();
        }
}

另外,还想问一下怎么限制上传图片的类型.最好帮忙加进上面的代码里,谢谢!!!

[ 本帖最后由 gjkitty 于 2007-9-26 12:06 编辑 ]

在服务器端判断:
$_FILES['userfile']['type']
文件的 MIME 类型,需要浏览器提供该信息的支持,例如“image/gif”。
客户端只有个笨方法,取得<input>的value值,取后三位字符串(例:jpg)然后判断