Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_FILES returns empty when using HTML Form and Dropzone JS

I have spent way too much time on this and browsed various questions/answers here on stackoverflow.

I am using dropzone.js to add a basic drag and drop upload feature to our HTML/PHP form. The drag and drop is working great however when the form is submitted or a file is uploaded the $_FILES returns empty and I cant figure it out.

I checked a tutorial and no luck, also checked some Q & A's from stackoverflow before posting here but nothing has helped.

Here is the form in its simplest form:

<form action="<? echo BASE_URL; ?>/process-uploads.php" method="POST" class="form-signin" role="form" enctype="multipart/form-data">

        <div class="upload_container dropzone">Drag & drop file here or

                <div class="fallback">
                    <input name="ad" type="file" />
                </div>
            </div><!--fileUpload btn btn-primary-->

        <div class="dropzone-previews"></div>

                <input class="btn btn-lg btn-primary btn-block btn-forward" style="background:#00a85a;" type="submit" name="submit" value="Next Step" />
            </form>

The JS is:

<script type="text/javascript">

var myDropzone = new Dropzone(".dropzone", { 
    url: "<? echo BASE_URL; ?>/process-uploads.php/",
    paramName: "ad",
    addRemoveLinks: true,
    //maxFiles: 1,
    autoProcessQueue: false,
    //uploadMultiple: false,
    acceptedFiles: "image/png",
    dictInvalidFileType: "This file type is not supported.",

});
</script>

And process-upload.php just checks to see if anything was sent, but returning empty:

<?php

if (!empty($_FILES)) {

    echo 'We have a file';

    if($_FILES['ad']) {
        echo 'We grabbed the ad<br />';

        echo '<pre>';
        var_dump($_FILES);
        echo '</pre>';
    }
}
?>

Any help would be greatly appreciated. For reference I already checked enyo's tutorial for combining a form with dropzone and php

like image 739
Derek Avatar asked Nov 01 '22 13:11

Derek


1 Answers

I had the same issue today getting no response, no error whatsoever when uploading a file and search through all SO questions, i read your code couple of time but no solution. i later found out that post_max_size = 8M is set too small, large files cannot be uploaded. Make sure you set post_max_size large enough, so kindly create/add this to your .htaccess file, i needed to upload a file of 2gb

php_value upload_max_filesize    2047M
php_value post_max_size          2047M
php_value max_execution_time     10800
like image 58
femotizo Avatar answered Nov 13 '22 19:11

femotizo