douyan4900 2016-08-06 16:59
浏览 25

无法从POST对象获取图像文件名[重复]

I'm trying to get the name of img file from html form, but browser shows me the following error: Notice: Undefined index: image in C:\xampp\htdocs\login tutorial\index.php on line 11

Notice: Undefined index: image in C:\xampp\htdocs\login tutorial\index.php on line 12

Here is my PHP code:

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;
    }

Here is my 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>

UPDATE: It looks like I did't get the image file... Any reason for that?

</div>
  • 写回答

1条回答 默认 最新

  • duanjing7298 2016-08-06 17:02
    关注

    Use html attribute form enctype="multipart/form-data"

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

    评论

报告相同问题?

悬赏问题

  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏