Pass value $ _FILES via Jquery [duplicate]

0

I have a form from which an attached file is sent via email. The problem is that when I upload the file, it does not seem to pass the value of $_FILES via formulário/jquery . See below:

HTML

<form role="form" class="contact-form" id="contact-form" method="post">
     <div id="success"></div>
     <div class="form-group">
         <label for="career-name">Nome</label>
         <input type="text" name="Nome" class="form-control" id="nome">
     </div>
     <div class="form-group">
          <label for="career-name">E-mail</label>
          <input type="text" name="Email" class="form-control" id="email">
     </div>
     <div class="form-group">
          <label for="career-name">Vaga pretendida</label>
          <input type="text" name="Vaga" class="form-control" id="vaga">
     </div>
     <div class="form-group">
          <label for="career-resume">Currículo</label>
          <input type="file" name="Arquivo" class="form-control" id="curriculo">
     </div>
     <button type="submit" class="btn btn-primary" id="submit"><i class="icon-ok"></i> Enviar</button>
</form>

JQUERY

<script type="text/javascript">
      $('#submit').click(function() {
      $.post("includes/enviar-curriculo.php", $(".contact-form").serialize(), function(response) {
          $('#success').html(response);
        $('#nome').val('');
        $('#email').val('');
        $('#vaga').val('');
        $('#mensagem').val('');
      $('#curriculo').val('');
        });
      return false;
      });
</script>

PHP FILE

<?php
....
$curriculo = $_FILES["Arquivo"];
echo $curriculo['name'];
....
?>

Is it possible to pass $_FILES values via Jquery?

    
asked by anonymous 14.11.2016 / 12:08

1 answer

0

Yes. In the event submit of your form, through your ajax you will send data as new FormData(this) . Here is an example.

<form name="form1" id="send" enctype="multipart/form-data">
  <input type="file" name="nome" />
</form>

and in your ajax

$.ajax({
  url: 'file.php',
  type: 'POST',
  data: new FormData(this),

  success: function(){  }
});

In your PHP you will capture the value as follows

<?php 
  echo $_FILES["nome"]["name"];
?>
    
14.11.2016 / 12:26