javascript - jQuery Ajax Upload File php recives array even with out content -


its working on every submit recive array tho file not added file input (multifile input)

    postdata = new formdata(this);      $.ajax({         url: "/url",         type: "post",         data: postdata,         cache: false,         contenttype: false,         processdata: false,         success: function (data, textstatus, jqxhr) {             if (data === "true") {                 window.location.replace("/url");             } else {                 $(".errors").html(data);             }         },         error: function (jqxhr, textstatus, errorthrown) {             swal("der opstod en fejl");         }     }); 

what $_files following

array (     [files] => array         (             [name] => array                 (                     [0] =>                  )              [type] => array                 (                     [0] =>                  )              [tmp_name] => array                 (                     [0] =>                  )              [error] => array                 (                     [0] => 4                 )              [size] => array                 (                     [0] => 0                 )          )  ) 

is there way can avoide happening ?

try adding required attribute input type="file" element prevent submission of form if no files selected user

$("form").on("submit", function(e) {    e.preventdefault();    // `$.ajax()` stuff  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">  </script>  <form>    <input type="file" name="files[]" multiple required />    <input type="submit" />  </form>


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -