Dropzone in sending email $ files empty

0

Good, I created a form with the Dropzone library, but when sending the variable $_FILES is always empty.

I've set up the library so that it does not self-execute, but it still ignores me.

The form (I paste only the header because it is too long)

<form method="POST" role="form" action="php/form.php" enctype="multipart/form-data" class="dropzone">

The dropzone.min.js

Dropzone.prototype.defaultOptions = {
  url: "php/form.php",
  method: "post",
  withCredentials: false,
  parallelUploads: 5,
  uploadMultiple: false,
  maxFilesize: 80000,
  paramName: "files",
  createImageThumbnails: true,
  maxThumbnailFilesize: 10,
  thumbnailWidth: 120,
  thumbnailHeight: 120,
  filesizeBase: 1000,
  maxFiles: null,
  params: {},
  clickable: true,
  ignoreHiddenFiles: true,
  acceptedFiles: "image/*,application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.openxmlformats-officedocument.presentationml.template, application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.presentationml.slide, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.template, application/vnd.ms-excel.addin.macroEnabled.12, application/vnd.ms-excel.sheet.binary.macroEnabled.12,text/rtf,text/plain,audio/*,video/*,.csv,.doc,.xls,.ppt,application/vnd.ms-powerpoint,.pptx",
  acceptedMimeTypes: null,
  autoProcessQueue: false,
  autoQueue: true,
  addRemoveLinks: true,
  previewsContainer: null,
  hiddenInputContainer: "body",
  capture: null,
  renameFilename: null,
  dictDefaultMessage: "Drop files here to upload",
  dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
  dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
  dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
  dictInvalidFileType: "You can't upload files of this type.",
  dictResponseError: "Server responded with {{statusCode}} code.",
  dictCancelUpload: "Cancel upload",
  dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
  dictRemoveFile: "Remove file",
  dictRemoveFileConfirmation: null,
  dictMaxFilesExceeded: "You can not upload any more files.",
  accept: function(file, done) {
return done();
  },
  init: function() {
    //return noop;
    var myDropzone = this;
        // First change the button to actually tell Dropzone to process the queue.
    this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
        // Make sure that the form isn't actually being sent.
            e.preventDefault();
        e.stopPropagation();
        myDropzone.processQueue();
        });
       // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
       // of the sending event because uploadMultiple is set to true.
    this.on("sendingmultiple", function() {
              // Gets triggered when the form is actually being sent.
              // Hide the success button or the complete form.
          });
          this.on("successmultiple", function(files, response) {
              // Gets triggered when the files have successfully been sent.
             // Redirect user or notify of success.
          });
          this.on("errormultiple", function(files, response) {
             // Gets triggered when there was an error sending the files.
            // Maybe show form again, and notify user of error
          });
  },

php destination form.php

    <?php

if(isset($_FILES)) {
    require '../phpMailer/PHPMailerAutoload.php';

    $body = "
        <html><head><title>Formulario Solicitud campaña</title></head>
        <body style='background:#EEE; padding:30px;'>
        <h2 style='color:#767676;'>Solicitud campaña de " . $_POST["Filial"] ." dia ". $_POST["FechaDemanda"] ."</h2>";
    $body .= "
        <strong style='color:#0090C6;'>Nombre: </strong>
        <span style='color:#767676;'>" . $_POST["NSolicitud"] . "</span><br>";
    $body .= "
        <strong style='color:#0090C6;'>Email: </strong>
        <span style='color:#767676;'>" . $_POST["ESolicitud"] . "</span><br>";
    $body .= "</body></html>";

    $asunto = "Solicitud campaña de " . $_POST["Filial"] ." dia ". $_POST["FechaDemanda"];


    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    $mail->setFrom($_POST["ESolicitud"], $_POST["NSolicitud"]);
    //$mail->addReplyTo($_POST["ESolicitud"], $_POST["NSolicitud"]);
    $mail->addAddress('[email protected]', 'Solicitud de campañas');
    //$mail->addAddress('[email protected]', 'Solicitud de campañas');
    $mail->AddCC($_POST["ESolicitud"], $_POST["NSolicitud"]);
    $mail->Subject = $asunto;
    $mail->msgHTML($body);

    /*if(is_uploaded_file($_FILES['files']['tmp_name'])) { 
        $mail->AddAttachment($_FILES['files']['tmp_name'], $_FILES['files']['name']);
    } */
    if (array_key_exists('files', $_FILES)) {
        //Attach multiple files one by one
            for ($ct = 0; $ct < count($_FILES['files']['tmp_name']); $ct++) {
            $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['files']['name'][$ct]));
                $filename = $_FILES['files']['name'][$ct];
            if (move_uploaded_file($_FILES['files']['tmp_name'][$ct], $uploadfile)) {
                        $mail->addAttachment($uploadfile, $filename);
                } else {
                    $msg .= 'Failed to move file to ' . $uploadfile;
                }
            }
    }

    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "<br>Message sent!";
    }

}
?>

I'm missing something to configure that I do not see? Thanks for any help you can give me.

    
asked by Irene 28.11.2016 в 11:52
source

1 answer

0

Good Irene,

The first thing is that I see that you are modifying the DropZone class with prototype instead of using an instance of it to modify the default values.

In some cases doing this in a plugin can cause you to lose reference to some internal variable of the plugin itself.

Surely you have done it but I leave you the dropzone tutorial link for PHP so you can review the implementation with PHP.

link

If you realize just adding the class to the form the plugin starts to work. I recommend doing a merge of the Dropzone.prototype.defaultOptions object to make sure you do not crush any property.

Greetings.

    
answered by 29.11.2016 в 10:32