troubleshooting Question

File upload

Avatar of tonelm54
tonelm54 asked on
JavaScriptWeb DevelopmentjQuery
5 Comments1 Solution76 ViewsLast Modified:
Ive been trying to figure out how to do my own file upload from a dropped file. Ive cobbled together from multiple articles and got the following:-
<!DOCTYPE html>
<html lang="en">
<script src="jquery-3.4.1.js"></script>

#testDiv {
    border: 1px solid black;

<div id="testDiv">nnn</div>

$(document).ready(function() {
$('#testDiv').on('dragover', function(e) {

$('#testDiv').on('dragenter', function(e) {

$('#testDiv').on('drop', function(e){
    if(e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {

function myOwnCallBack(file) {
    let data = new FormData();

    for(var i = 0;i<file.length;i++){
        data.append("file_"+i, file[i]);
    data.append("test1", "value1");
    data.append("test2", "value2");

        data: data,
        type: "POST",
        url: "file-uploader.php",
        cache: false,
        contentType: false,
        processData: false,
        xhr: function() {
            let myXhr = $.ajaxSettings.xhr();
            if (myXhr.upload) myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
            return myXhr;
        success: function(reponse) {

function progressHandlingFunction(e) {
    if (e.lengthComputable) {
        console.log((e.loaded / * 100) + '%');

        if (e.loaded === {
            console.log("Upload finished.");

My test values transfer fine, but the file(s) dont transfer.

Can anyone see what Im doing wrong with the files?

Thank you in advance
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros