Search This Blog

2017/03/08

Upload files by drag&drop

html part:
<div style="display: none;">
    <form action="upload.php" method="post" enctype="multipart/form-data" id="form">
        <input type="file" name="file" id="file">
    </form>
</div>
<div id="dropArea" style="height:25px">drop image here</div>
JS:
$("#dropArea").on("drop dragover", function(e) {
    var fm = document.getElementById('form');
    var fd = new FormData(fm);
    imageUpload(fd);
});

function imageUpload(fd) {
    $.ajax({
        async: true,
        type: 'post',
        url: 'upload.php',
        data: fd,
        contentType: false,
        processData: false,
        timeout: 120000,
        success: function(data) {
        },
        error: function(R, S, E){}
    });
}

No comments :

Post a Comment