Problems uploading images with the Dropzone library

Asked

Viewed 193 times

0

I’m using the library Dropzone, it is working the only problem is that the selected files do not reach the server, always returns me Undefined index files, what could be?

The form looks like this:

<h4 class="card-title">Escolha as imagens do seu anúncio</h4>
<form method="POST" id="myFirstDropzone" action="<?= base_url('Anunciante/adicionarImagens'); ?>" class="dropzone" enctype="multipart/form-data">
    <div class="fallback"> 
      <input name="files[]" type="file" multiple> 
    </div>
</form>

Javascript

 Dropzone.options.myFirstDropzone = {
            paramName: "files", 
            maxFilesize: 2, // MB
            autoProcessQueue: false,
            uploadMultiple: true,
            parallelUploads: 3,
            maxFiles: 3
});


$("#btn-adicionar-img").click(function(){
   $("#myFirstDropzone").submit(); 
});

Controller

public function adicionarImagens(){
    echo '<pre>';
    var_dump($_FILES['files']);
    echo '</pre>';
    die();
    $this->anunciante->adicionaImagens($_FILES['files'], $this->session->userdata('id_anuncio'));
}
  • what is the result of var_dump($_FILES['files']);?

  • The PHP Error was encountered Severity: Notice Message: Undefined index: files

  • The name of your input is files[], you shouldn’t index the same way in php? Seria $_FILES['files[]']

  • Of course not, this does not even exist face, I’m sending an array with the name files, in each position will an image

1 answer

0


I got it this way

<form method="POST" enctype="multipart/form-data" id="myFirstDropzone" action="<?= base_url('Anunciante/adicionarImagens'); ?>" class="dropzone">

                </form><button type="button" id="btn-upload" class="btn btn-primary">Salvar imagens</button>

When you click the button you will start uploading the files:

  Dropzone.autoDiscover = false;

        var myDropzone = new Dropzone('#myFirstDropzone', {
            paramName: "files",
            maxFilesize: 3.0,
            maxFiles: 4,
            parallelUploads: 10000,
            uploadMultiple: true,
            autoProcessQueue: false
        });

        $('#btn-upload').on('click', function () {
            myDropzone.processQueue();
        });

Very simple guys, for those who need it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.