这是我以前写的一个上传附件的程序
通过判断文件扩展名。。
注意:我上传后的文件名加了session_id的<?require("/home/www/htdocs/common.php");
auth();$permission_ext = array("JPG","GIF","ZIP","RAR","HTML","HTM","TXT");
?>
<html>
<title>附件上传</title>
<style>
body{font-size:9pt;background:#F4F1D9;}
</style>
<link rel="stylesheet" type="text/css" href="/style.css"><body topmargin=4>
<form enctype="multipart/form-data" action=<? print("$PHP_SELF method=post>");?>
<?
if($myfile!="" && $myfile_size > 0){
$ext = strtoupper( substr($myfile_name,strrpos($myfile_name,".") + 1) );

if(in_array($ext,$permission_ext))
{
         copy($myfile,"./tmp/".session_id().$myfile_name) or die("上传错误!");
         @chmod("./tmp/".session_id().$myfile_name,0777);
         $string = "<font color=red>上传成功,你只需要完成发言就会将该附件加入你的发言。</font><br>";
        }
        else
        {
         $string = "<font color=red>错误!文件类型不允许!</font><br>";
        }
}
print "<center>$string";;
?>
文件: <input name="myfile" type="file">
<br><br>
<input type="submit" value="送出" class=button>
 <input type=reset onclick=window.close() class=button value=取消>
</form>