//1.主页面0523shangcuan.p <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <form action="chuli.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" name="上传" /> </form> </body> </html> //处理的页面chuli.php <?php if(!$_FILES[file][error]);//判断文件上传是否出错 { if($_FILES["file"]["type"]=="image/png"||$_FILES["file"]["type"]=="image/jpeg" &&($_FILES["file"]["size"]<=1048576))//限制上传文件的类型和文件的大小 { //造文件存储路径 $filename="./mga/".$_FILES["file"]["type"]; //处理文件编码格式 $filename=iconv("UTF-8","gb2312",$filename); //判断文件名是否重复 if(file_exists($filename)) { echo "该文件名已存在!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],$filename);//上传文件(移动文件) } } else { echo"上传的文件类型不支持!"; } } else { echo "文件上传失败!"; }