注意未定义的索引:图片

时间:2018-06-25 17:17:35

标签: php

我收到此错误未定义索引:image,并且我已经从互联网上应用了一些建议,以检查文件是否为空并匹配输入类型内部已使用的名称。

这就是我的代码

  

表格

<form accept-charset="UTF-8" method="POST" 
action="../includes/user-management/signup.inc.php" 
enctype="multipart/form-data" class="form" id="myform">
  

input type =“ file”

<p class="form-field ">
<label class="field-label" style="text-align:center";>Upload an Image</label><p></p>
   <input type="file" id="myFile" name="image" accept="image/*" size="30" required></p>
  

脚本

<script type="text/javascript">
 $(document).ready(function(){
$('#myform').validate({
    rules: {
      email: {
        required: true,
        email: true
      },
      password: {
        required: true,
        minlength: 8
      }       
    },
    // Specify validation error messages
    messages: {
      password: {
        required: "Please provide a password",
        minlength: "Your password must be at least 8 characters long"
      }
    },
     submitHandler: subform
  });
    function subform(){
            var data = $("#myform").serialize();
            $.ajax({
                type: 'POST',
                url: '../includes/user-management/signup.inc.php',
                data: data,
                beforeSend: function(){
                    $("#info").fadeOut();
                    $("#submit").html("Signing-up...");
                },
                success: function(resp){
                    if(resp=="success"){
                        $("#submit").html("<img src='ajax-loader.gif' width='15'/> &nbsp; Signing-up");
                        setTimeout('window.location.href = "../index.php";',4000);
                    } else{
                        $("#info").fadeIn(1000, function(){
                            $("#info").html("<div class='text-danger'>"+resp+"</div>");
                            $("#submit").html('Sign-up');
                        })
                    }
                }
            })
        }   
  });

</script>
  

signup.inc.php(不完整的副本,     我只是透露了我在哪里应用$ _FILES ['image'] ['name'])

<?php
session_start();
if (isset($_POST['_utf8']) && !empty($_FILES['image'])) {

include_once '../connection/dbh.inc.php';
echo "i'm in";
$firstName = trim(mysqli_real_escape_string($conn, $_POST['firstName']));
$lastName = trim(mysqli_real_escape_string($conn, $_POST['lastName']));
$email = trim(mysqli_real_escape_string($conn, $_POST['email']));
$password = trim(mysqli_real_escape_string($conn, $_POST['password']));
$businessPermit = basename($_FILES['image']['name']);

} else {
echo "error";
 echo "<pre>". var_dump($_FILES['image']) . "</pre>";
exit();
}

var_dump显示NULL btw 提前致谢 !

0 个答案:

没有答案