Skip to content

Instantly share code, notes, and snippets.

@luisdalmolin
Created February 9, 2018 21:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luisdalmolin/87bbfb9a32e8ddf8d11111832c3f5003 to your computer and use it in GitHub Desktop.
Save luisdalmolin/87bbfb9a32e8ddf8d11111832c3f5003 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<div class="h-64 border-solid border-black border-4 text-center" id="dropzone">
Drop files here
</div>
<form action="test.php" enctype="multipart/form-data" method="post">
<input type="file" name="files[]" id="files" multiple>
<button type="submit">Send</button>
</form>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
var $dropzone = $('#dropzone');
$dropzone.on('drag dragstart dragend dragover dragenter dragleave drop', function (event) {
event.preventDefault();
event.stopPropagation();
}).on('drop', function(event) {
document.querySelector('#files').files = event.originalEvent.dataTransfer.files;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment