1、主页:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form method="post" action="upload.php" enctype="multipart/form-data">
        <input type="file" name="file">
        <input type="submit" value="上传">
    </form>
</body>
</html>

2、处理页面:

<?php
$types = ['image/jpeg','image/png'];
//in_array()
if(!$_FILES['file']['error']){
    if(in_array($_FILES['file']['type'],$types) ){
        if($_FILES['file']['size']<2000000){
            $file_name = "./upload/".'123'.$_FILES['file']['name'];
            if(!file_exists($file_name)) {
                move_uploaded_file($_FILES['file']['tmp_name'], $file_name);
            }else{
                echo "文件已存在";
            }
        }else{
            echo "文件过大";
        }
        }else{
            echo "格式不符合要求";
        }
        }else{
            echo "上传失败";
        }