0

Buenas, he creado un formulario con la libreria Dropzone, pero al enviar la variable $_FILES esta siempre vacia.

He configurado la libreria para que no se autoejecute, pero aun asi sigue sin hacerme caso.

El formulario (pego solo la cabecera porque es muy largo)

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

El 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 destino 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!";
    }

}
?>

Me falta algo por configurar que no veo? Gracias por cualquier ayuda que me podais dar.

1 respuesta 1

0

Buenas Irene,

Lo primero es que veo que estas modificando la clase DropZone con prototype en lugar de usar una instancia de la misma para modificar los valores por defecto.

En algunos casos el hacer esto en un plugin puede hacer que se pierda referencia a alguna variable interna del propio plugin.

Seguramente lo hallas hecho pero te dejo el link del tutorial de dropzone para PHP para que puedas revisar la implementacion con PHP.

https://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php

Si te das cuenta solo con añadir la clase al formulario el plugin empieza a funcionar.Te recomiendo hacer un merge del objeto Dropzone.prototype.defaultOptions para asegurarte de que no machacas ninguna propiedad.

Un saludo.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.