title: bootstrap modal upload file
body: <p>I'm having a problem to upload a file using bootstrap modal upload file
  This is my modal code</p>
  
  <pre><code>&lt;div id="myModalAtiv" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
          &lt;div class="modal-dialog modal-lg"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                      &lt;h4 class="alert alert-info" id="myModalLabel"&gt;&lt;span class="glyphicon glyphicon-pencil"&gt;&lt;/span&gt; Edição de Atividades&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;form class="form-horizontal" id="formacoes" enctype="multipart/form-data"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="hidden" name="idformacao" id="idformacao"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Escola:&lt;/label&gt;
                              &lt;input class="form-control" name="escola" id="escola" disabled="true"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Nome:&lt;/label&gt;
                              &lt;input class="form-control" name="nome" id="nome"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Data:&lt;/label&gt;
                              &lt;div class="input-group date" id="datetimePicker"&gt;
                              &lt;input type="text" class="form-control" name="inicio" id="inicio" /&gt;
                              &lt;span class="input-group-addon"&gt;&lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
                          &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Horas:&lt;/label&gt;
                              &lt;input class="form-control" name="horas" id="horas"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Local:&lt;/label&gt;
                              &lt;input class="form-control" name="local" id="local"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Destinatários:&lt;/label&gt;
                              &lt;input class="form-control" name="destinatarios" id="destinatarios"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="recipient-name" class="control-label"&gt;Data Limite:&lt;/label&gt;
                              &lt;div class="input-group date" id="dataLimitePicker"&gt;
                              &lt;input type="text" class="form-control" name="dataLimite" id="dataLimite" /&gt;
                              &lt;span class="input-group-addon"&gt;&lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
                              &lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="fileupload fileupload-new" data-provides="fileupload"&gt;
                          &lt;div class="input-append"&gt;
                            &lt;div class="uneditable-input span3"&gt;&lt;i class="icon-file fileupload-exists"&gt;&lt;/i&gt; 
                              &lt;span class="fileupload-preview"&gt;&lt;/span&gt;&lt;/div&gt;
                              &lt;span class="btn btn-file"&gt;&lt;input type="file" name="fileToUpload" id="fileToUpload" /&gt;&lt;/span&gt;
                          &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="modal-footer"&gt;
                              &lt;button type="submit" class="btn btn-info"&gt;Atualizar&lt;/button&gt;
                              &lt;button type="button" class="btn btn-default"data-dismiss="modal"&gt;Fechar&lt;/button&gt;
                          &lt;/div&gt;     
                      &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;&lt;!-- End of Modal body --&gt;
      &lt;/div&gt;&lt;!-- End of Modal content --&gt;
  </code></pre>
  
  <p>and this is my ajax function to send the form</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function () {
          $('#datetimePicker').datetimepicker({format: 'YYYY-MM-DD'});
          $('#dataLimitePicker').datetimepicker({format: 'YYYY-MM-DD'});
          $('#formacoes').formValidation({
              framework: 'bootstrap',
              icon: {
                  valid: 'glyphicon glyphicon-ok',
                  invalid: 'glyphicon glyphicon-remove',
                  validating: 'glyphicon glyphicon-refresh'
              },
              fields: {
                  nome: {
                      validators: {
                          notEmpty: {
                              message: 'Tem de definir alguma formação'
                          }
                      }
                  }
              },inicio: {
                      validators: {
                          notEmpty: {
                                  message: 'Data inicial obrigatória'
                              },
                          date: {
                              format: 'YYYY-MM-DD',
                              message: 'Data inicial inválida'
                          }
                      }
                  },
                  dataLimite: {
                      validators: {
                          notEmpty: {
                                  message: 'Data limite obrigatória'
                              },
                          date: {
                              format: 'YYYY-MM-DD',
                              message: 'Data limite inválida'
                          }
                      }
                  }
          }).on('success.form.fv', function (e) {
              e.preventDefault();
              var $form = $(e.target),
                      fv = $form.data('formValidation');
              $.ajax({
                  url: 'updates.php',
                  type: 'POST',
                  data: $form.serialize(),
                  success: function (response) {
                      console.log(response.status);
                      if (response.status === 'success') {
                          $("#myModalAtiv").modal('hide');
                          $('#respostas .modal-title').html('Sucesso');
                          $('#respostas .modal-body').html('Informação: ' + response.message);
                          $('#respostas').modal('show');
                          $('#respostas').on('hidden.bs.modal', function () {
                              window.location.reload(true);
                          });
                      }
                  }
              });
          });
      });
  </code></pre>
  
  <p>All seems to be ok, but when i trying to send the from to my function it says</p>
  
  <p>Notice: Undefined index: fileToUpload </p>
  
  <p>This is my php function</p>
  
  <pre><code>$idformacao= filter_input(INPUT_POST, 'idformacao');
  if ($idformacao != null) {
      echo "aqui";
      $userid = filter_input(INPUT_POST, 'userid');
      $nome = filter_input(INPUT_POST, 'nome');
      $inicio = filter_input(INPUT_POST, 'inicio');
      $horas = filter_input(INPUT_POST, 'horas');
      $local = filter_input(INPUT_POST, 'local');
      $destinatarios = filter_input(INPUT_POST, 'destinatarios');
      $dataLimite = filter_input(INPUT_POST, 'dataLimite');
      $uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/uploads';
      $uploadfile = $uploaddir . '/' . basename($_FILES['fileToUpload']['name']);
      if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile)) {
      $target_path = "/uploads/" . basename($_FILES['fileToUpload']['name']);
      $ret = $ebspma-&gt;updateFormacoes($idformacao, $nome, $inicio, $horas, $local, $destinatarios, $dataLimite,$target_path);
      }
      echo json_encode($ret); 
  }
  </code></pre>
  
  <p>And this is the line where i have the error</p>
  
  <pre><code> $uploadfile = $uploaddir . '/' . basename($_FILES['fileToUpload']['name']);
  </code></pre>