我试图实现HTML5拖放上传文件。当文件被删除时,我想调用php文件来处理掉落的文件。我如何调用php文件并访问php文件中的拖动文件。此外,我想从PHP文件中发回成功或错误消息。HTML5拖放问题
我无法弄清楚如何将文件发布到php并从那里获得响应。 到目前为止我的代码是:
function drop(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files;
handleFiles(files);
}
function handleFiles(files) {
var file = files[0];
var reader = new FileReader();
reader.onload = uploadFile; //main function
reader.onloadend = uploadComplete;
reader.readAsDataURL(file);
}
function uploadFile(evt)
{
//call upload.php
//get success msg or error msg
//alert(success) or alert(error)
}
这里的例子upload.php的文件:
<?php
$dropped_file //how to get the file
if (filesize($dropped_file) > 1024)
{
echo "size error" //how to send this error
}
else
{
echo "success" //how to send this success msg.
}
?>
我不建议使用jQuery UI这个下降的能力。很可能有更轻,更清洁的解决方案。 – Bojangles