-
-
Save mehrshaddarzi/465f052c7d937547eecaaabee1e055c5 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/puteru/11
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<style> | |
#holder.hover { border: 10px dashed #0c0 !important; } | |
</style> | |
<form method="post" action="http://httpbin.org/post" enctype="multipart/form-data"> | |
<input id="name"><br/> | |
<input id="type"><br/> | |
<input id="size"><br/> | |
<input id="modified"><br/><br/> | |
<div id="holder" style="width:200px; height:200px; border: 10px dashed #ccc" id="holder"></div> | |
</form> | |
<script> | |
var holder = document.getElementById('holder'); | |
holder.ondragover = function () { this.className = 'hover'; return false; }; | |
holder.ondragend = function () { this.className = ''; return false; }; | |
holder.ondrop = function (e) { | |
this.className = ''; | |
e.preventDefault(); | |
upload(e.dataTransfer.files); | |
}; | |
/////////////////////////////// | |
function upload(files) { | |
document.getElementById('name').value = files[0].name; | |
document.getElementById('size').value = files[0].size; | |
document.getElementById('type').value = files[0].type; | |
document.getElementById('modified').value = files[0].lastModifiedDate; | |
var formData = new FormData(); | |
formData.append('img',files[0]); | |
//post the form data yourself, but it's ready to go | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment