integrating Dropzone with self-sufficient form PHP

Viewed 50

Hello have an issue url option doesn't work in dropzone. dropzone works well but have an issue with uploading to the folder for sending into email.

Can help me? how I can send images from dropzone into PHP file for future processing and move them into a certain folder? enter image description here

Here is my code of form

  <form action="send.php" method="post">
            <input type="hidden" name="token" value="<?php echo $_SESSION['token'] ?? '' ?>">
            <div class="rating_wrapper">
                <?php 
                    for ($i=1; $i <=6 ; $i++) { 
                        ?>
                        <div class=" rating_box">
                            <img src="img/human_grey.png">
                                <input type="radio" name="rating" id="rating-<?= $i ?>" value="<?= $i ?>">
                                <label for="rating-<?= $i ?>" class="rating-input__box">
                                    <div class="rating-checked"></div>
                                    <div class="rating_number">
                                        <?= $i ?>
                                    </div>
                                </label>
                        </div>
                <?php                        
                    }
                    for ($i=7; $i <=8 ; $i++) {
                        ?>
                        <div class=" rating_box">
                            <img src="img/human_white.svg">
                            <input type="radio" name="rating" id="rating-<?= $i ?>" value="<?= $i ?>">
                            <label for="rating-<?= $i ?>" class="rating-input__box">
                                <div class="rating-checked"></div>
                                <div class="rating_number">
                                    <?= $i ?>
                                </div>
                            </label>
                        </div>
                <?php
                    }
                    for ($i=9; $i <=10 ; $i++) {
                        ?>
                        <div class=" rating_box">
                            <img src="img/human_green.svg">
                            <input type="radio" name="rating" id="rating-<?= $i ?>" value="<?= $i ?>">
                            <label for="rating-<?= $i ?>" class="rating-input__box">
                                <div class="rating-checked"></div>
                                <div class="rating_number">
                                    <?= $i ?>
                                </div>
                            </label>
                        </div>
                <?php
                    }
                    ?>
            </div>
            <div class="measurement">
                <div class="measurement_low">Not at all likely</div>
                <div class="measurement_arrow"></div>
                <div class="measurement_hight">Extremely likely</div>
            </div>

            <h3>please explain <span class="accent">why you gave this score </span></h3>
            <div class="o-constrained">
                <div  class="c-dropzone">
                    <textarea class="c-dropzone__textarea" name="message" cols="30" rows="10"></textarea>
                <!--begin::Input group-->
                    <div class="dropzone" id="kt_dropzonejs_example_1">
                        <!--begin::Message-->
                        <div class="dz-message needsclick">
                            <!--begin::Icon-->
                            <i class="bi bi-file-earmark-arrow-up text-primary fs-3x"></i>
                            <!--end::Icon-->
                            <!--begin::Info-->
                            <div class="ms-4">
                                <div id="upload-label" >
                                    <img class="upload-icon" src="img/icons8.png">
                                </div>
                                <!--end::Info-->
                            </div>
                        </div>
                        <!--end::Dropzone-->
                    </div>
                </div>
            </div>
            <div class="form-fields">
                <input  type="textarea" 
                        placeholder="your name"
                        name="sname"
                >
                <input  type="tel" id="phone" name="phone"
                        placeholder="your phone number"
                        required>
                <input  type="email" id="email"
                        placeholder="your email"
                        name="email"
                      
                        size="30"
                        required>
            </div>
            <div class="submit-area">
                <div class="contact-me">
                    <input type="checkbox" name="contact-me" id="contact-me">
                    <label for="contact-me">You may contact me for more details</label>
                </div>
                <div class="policy">
                    By giving us feedback you agree that Eumar can use your feedback to improve our products and services. Privacy statement
                    <input type="submit" value="submit">
                </div>
            </div>
        </form>

My dropzone script

<script type="text/javascript">
var myDropzone = new Dropzone("#kt_dropzonejs_example_1", {
    url: "upload.php", // Set the url for your upload script location
    url: "upload.php", // Set the url for your upload script location
    paramName: "file", // The name that will be used to transfer the file
    maxFiles: 10,
    
    clickable: "#upload-label",
    maxFilesize: 10, // MB
    addRemoveLinks: true,
      acceptedFiles: "image/*",
    accept: function(file, done) {
        if (file.name == "wow.jpg") {
            done("Naha, you don't.");
        } else {
            console.log('success');
            done();
        }
    }
});
</script>

My upload.php file

$folder_name = 'upload/'.$_SESSION['token'].'/';
if (!empty($_FILES)) {
    if (!mkdir($folder_name, 0777, true)) {
        die('Failed to create directories...');
    }
    $temp_file = $_FILES['file']['tmp_name'];
    $location = $folder_name . $_FILES['file']['name'];
    move_uploaded_file($temp_file, $location);
}
if (isset($_POST["name"])) {
    $filename = $folder_name.$_POST["name"];
    unlink($filename);
}
0 Answers
Related