Last active
July 18, 2018 10:09
-
-
Save portapipe/e88efc03e375bb059b28ae629f95a30a to your computer and use it in GitHub Desktop.
Drag&Drop native file upload jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.js"></script> | |
<style> | |
.dropzones{ | |
border: 2px dashed grey; | |
height: 80px; | |
text-align: center; | |
padding-top: 40px; | |
cursor: pointer; | |
} | |
#file{ | |
display:none; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="dropzones" onclick="apri_scelta_file();"> | |
CLICK OR DRAG HERE<br/> | |
CLICCA O TRASCINA QUI | |
</div> | |
<form action="" id="form" class="" method="post" enctype="multipart/form-data"> | |
<input type="file" name="file" class="hidden" id="file" /> | |
</form> | |
<script> | |
function apri_scelta_file(){ | |
$('#file').click(); | |
} | |
$(document).on("dragover drop", function(e) { | |
e.preventDefault(); }).on("drop", function(e) { | |
$("input[type='file']") | |
.prop("files", e.originalEvent.dataTransfer.files) | |
.closest("form") | |
.submit(); // autosubmit | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment