I am learning drag and drop file upload. Is this following method can be used for uploading file. it is just a simple program where if i upload image via input type="file"; i can get the file information in array format but if i use drag and drop method; i get following output. thank you in advance....
home.html
<html>
<head>
<title>try try</title>
<link href="style.css" rel="stylesheet"></link>
<script src="jquery.js"></script>
<script src="upload.js"></script>
</head>
<body>
<form id="upload">
<div style="display:block; width:300px; height:300px;border:4px dashed #ccc;" id="upload_area" ondragover="return false"></div>
<span class="result" style="border:1px solid black;"></span>
</form>
</body>
upload.js
$(document).ready(function(){
jQuery.event.props.push('dataTransfer');
$('#upload_area').bind('drop', function(e) {
var files = e.dataTransfer.files;
var formobj = document.getElementById("upload");
var ans = new FormData(formobj);
$.ajax({
type:"post",
data:ans,
cache : false,
url:"upload.php",
processData:false,
contentType:false,
success:function(response){
$(".result").html(response);
}
})
return false;
});
})
upload.js
<?php
echo "<pre>";
print_r($_FILES);
echo "</pre>";
?>
Output
array()