#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,189
    Rep Power
    220

    How to get Dropzone.js to update input values and post?


    Hi I use Dropzone.js to drag files for upload.

    It's almost there ( Here is the fiddle ).

    When I post, on the next page php print_r($_POST) doesn't have any value for input "file".

    Here is what I get from printr($_FILES)
    PHP Code:
    Array ( [file] => Array ( [name] => [type] => [tmp_name] => [error] => [size] => ) ) 
    What am I doing wrong?

    Thanks
    Last edited by English Breakfast Tea; August 2nd, 2017 at 06:13 AM.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,079
    Rep Power
    4101
    You shouldn't have your file input (or it should be in a class="fallback" element). Dropzone.js will immediately upload the files to your server once they are dropped, then it appends the response to the form.

    So what you'd have on the server side is something like
    Code:
    if (isset($_FILES['file'])){
        $data = SaveUploadSomewhere($_FILES['file']);
        echo '<input type="checkbox" value="'.$data['id'].'" name="files[]"> '.htmlspecialchars($data['name']);
        exit;
    }
    Basically you accept the uploaded file, generate a reference to it then return that reference as an input to be added to the form.

    Then when you post the final form you gather those references and link up the files as needed.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo