可以';t从POST对象获取图像文件名


Can't get image file name from POST object

我试图从html表单中获取img文件的名称,但浏览器显示以下错误:注意:未定义的索引:在C:''examplep''htdocs''login tutorial''index.php中的第11行中的图像

注意:第12行C:''examplep''htdocs''login tutorial''index.php中的未定义索引:image

这是我的PHP代码:

if(isset($_POST['submit'])){
        $firstName = $_POST['fname'];
        $lastName = $_POST['lname'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $firstName = $_POST['fname'];
        $passwordConfirm = $_POST['confPassword'];
        $imageName = $_FILES['image']['name'];
        $imageSize = $_FILES['image']['size'];
        echo $firstName . "<br>" . $lastName . "<br>" . $email . "<br>" . $password . "<br>"
        . $passwordConfirm . "<br>" . $imageName . "<br>" . $imageSize;
    }

这是我的HTML:

<form method="post" action="index.php" enctype="multipart/form-data ">
                <label for="fname">First Name</label><br>
                <input type="text" name="fname" id="fname"><br>
                <label for="lname">Last Name</label><br>
                <input type="text" name="lname" id="lname"><br>
                <label for="email">Email</label><br>
                <input type="text" name="email" id="email"><br>
                <label for="password">Password</label><br>
                <input type="password" name="password" id="password"><br>
                <label for="confPassword">Confirm Password</label><br>
                <input type="password" name="confPassword" id="confPassword"><br>
                <input type="file" name="image"><br>
                <input type="submit" name="submit">
            </form>

更新:看起来我没有得到图像文件。。。有什么原因吗?

使用html属性表单enctype="multipart/form-data"

示例:<form action="." method="post" enctype="multipart/form-data">