使用jj发送图像时使用jQuery错误上传图片的人员

I have an error when I try to upload an image using jQuery and ajax.

Here is my html:

<label for="img_add_galery">
                    <a class="add">
                        <img click="image_galery" src="../../img/ui/black.png" alt="images">
                    </a>
                  </label>
                </div>
                <input type="file" id="img_add_galery" name="img_add_galery" style="display:none;"/>

This is my js:

$(document).on('change','#img_add_galery',function(){
    var property = document.getElementById('img_add_galery').files[0];
    var image_name = property.name;
    var image_extension = image_name.split('.').pop().toLowerCase();
    if(jQuery.inArray(image_extension, ['gif','png','jpg','jpeg']) == -1)
    {
      alert('invalid image type');
    }
    var image_size = property.size;
    if(image_size > 2000000000000)
    {
      alert('image is to big');
    }
    else
    {
      console.log(property);
        var form_data = new FormData();
        form_data.append("file", property);
        $.ajax({
          url: "traitement/add_image_galery.php",
          method: "POST",
          data: form_data,
          contentType:false,
          cache:false,
          processData:false,
          success:function(data)
          {
            $(".tz-gallery").children().append(data);
        }
      })
  }
})

and my php

var_dump($_FILES["img_add_galery"]["name"]);

if($_FILES["file_img"]["name"] != '')

{

  $test = explode(".",$_FILES["file_img"]["name"]);

  $extension = end($test);

  $name = rand(1,9999) . '.' . $extension;

  $location = '../../../img/galerie/'.$name;

  move_uploaded_file($_FILES["file_img"]["tmp_name"],$location);

  echo '<div class="col-sm-6 col-md-4">
      <a class="delete" img="'.$location.'">
          <img click="image_galery" src="'.$location.'" alt="images">
      </a>
  </div>';
}

When you append the file to your FormData object you use file as its name but in PHP you use file_img, both must match.

$_FILES["file"]["name"]

In fact, I think you should use the same name everywhere just to avoid confusion

<input type="file" id="img_add_galery" name="img_add_galery" style="display:none;"/>
form_data.append("img_add_galery", property);
$_FILES["img_add_galery"]["name"]

Also if you want to check what's going on in the file array you should dump the whole thing var_dump($_FILES);