<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <form action="doAction.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000000"> 上传项目文件: <input type="file" name="myFile" id="File" /><br/> <input type="submit" value="上传"/> </body> </html> /*DOACTION.PHP*/ <?php header('content-type:text/html;charset=utf-8'); print_r($_FILES); $file_name=$_FILES['myFile']['name']; $file_type=$_FILES['myFile']['type']; $file_tmpname=$_FILES['myFile']['tmp_name']; $file_size=$_FILES['myFile']['size']; $file_error=$_FILES['myFile']['error']; $maxsize=3145728;//限制上传最大的字节数 $allowed_file_type=array('doc','docx','wps','pdf'); $flag=true;//检测上传文件是否符合要求的返回值 //move_uploaded_file($file_tmpname,"php/".$file_name); //copy($file_tmpname,"php/".$file_name); if($file_error==0) { if($file_size>$maxsize) {exit('上传文件过大,请上传不大于30M的文件。');} $ext=pathinfo($file_tmpname,PATHINFO_EXTENSION); if(!in_array($ext,$allowed_file_type)) {exit("文件的类型不符!");} if(!is_uploaded_file($file_tmpname)) {exit("文件不是通过HTTP POST方式上传上来的");} //确保文件名不重复 $uniName=md5(uniqid(microtime(true),ture)).'.'.$ext; //设置上传文件存储目录 $path='upload'; $dst=$path.'/'.$uniName; if(@move_uploaded_file($file_tmpname,$dst)) {echo"文件上传成功";} else {echo"文件上传失败";} } else { switch($file_error){ case 1: echo"BEYOND THE MAXSIZE OF ALLOWED FILE SETTING";break; case 2: echo"超过表单MAX_FILE_SIZE限制大小";break; case 3: echo"文件被部分上传";break; case 4: echo"没有选择上传文件" ;break; case 6: echo"没有找到临时目录";break; case 8: echo"系统错误";break; } } ?>
PATHINFO($file_name,PATHINFO_EXTNSION),你改成这个实施