我在互联网上观看了许多链接,并且还提到了与此主题相关的每个问题,但没有一个帮助!所以请检查这段代码并告诉我我哪里做错了?
html代码:
<div class="drop_zone">
<p>Drop Here</p>
</div>
<form enctype="multipart/form-data" id="yourregularuploadformId">
<input type="file" name="files[]" multiple="multiple">
</form>
jQuery和javascript代码:
function handleFiles(droppedFiles) {
var uploadFormData = new FormData($("#yourregularuploadformId")[0]);
if(droppedFiles.length > 0) { // checks if any files were dropped
for(var f = 0; f < droppedFiles.length; f++) { // for-loop for each file dropped
alert(droppedFiles[f]['name']);
uploadFormData.append("files[]",droppedFiles[f]); // adding every file to the form so you could upload multiple files
}
}
// the final ajax call
alert(uploadFormData);
$.ajax({
url : "try.php", // use your target
type : "POST",
data : uploadFormData,
cache : false,
contentType : false,
processData : false,
success : function(ret) {
alert(ret);
}
});
return false;
}
$(document).ready(function() {
//alert("im in");
$('.drop_zone').bind("dragenter", function(e) {
// $('#StatusDrag').html('Drop The files Here...');
});
$('.drop_zone').bind("dragleave", function(e) {
// $('#StatusDrag').html('Drag and Drop Files Here to Share');
});
$('.drop_zone').bind("dragover", function(e) {
e.preventDefault();
return false;
});
$('.drop_zone').bind("drop", function(e) {
e.preventDefault();
e.stopPropagation();
e.originalEvent.preventDefault();
e.originalEvent.stopPropagation();
// $('#dragBox, #topDiv').hide();
var dt = e.originalEvent.dataTransfer;
var files = dt.files;
handleFiles(files);
});
});
php代码:
<?php
if(isset($_FILES["files"]))
{
foreach ($_FILES["files"] as $file)
echo $file['name'];
}
?>