Php HTML5拖放问题
我正在尝试实现HTML5拖放来上传文件。当文件被删除时,我想调用php文件来处理删除的文件。如何调用php文件并访问php文件中的拖动文件。另外,我想从php文件返回成功或错误消息 我不知道如何将文件发布到php并从那里获得响应。 到目前为止,我的代码是:Php HTML5拖放问题,php,html,Php,Html,我正在尝试实现HTML5拖放来上传文件。当文件被删除时,我想调用php文件来处理删除的文件。如何调用php文件并访问php文件中的拖动文件。另外,我想从php文件返回成功或错误消息 我不知道如何将文件发布到php并从那里获得响应。 到目前为止,我的代码是: function drop(evt) { evt.stopPropagation(); evt.preventDefault(); var files = evt.dataTransfer.f
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,在drop回调时执行AJAX调用
$("body").droppable({
accept: "img", //Your element type goes here e.g. img
drop: function(event, ui){
//Perform an AJAX call here. You can access the current dropped item through
//ui.draggable
}
)}
您可以使用jQuery,在drop回调时执行AJAX调用
$("body").droppable({
accept: "img", //Your element type goes here e.g. img
drop: function(event, ui){
//Perform an AJAX call here. You can access the current dropped item through
//ui.draggable
}
)}
使用jQuery UI将使您能够以最简单的方式拖放使用jQuery UI将使您能够以最简单的方式拖放我不建议为此使用jQuery UI。很可能有更轻、更干净的解决方案。我不建议为此使用jQueryUI。很可能有更轻、更清洁的解决方案。这不是一个有用的答案。如果您确实相信jQueryUI有一些很好的拖放功能,那么您至少可以链接到文档,这不是一个有用的答案。如果您确实相信jQueryUI有一些很好的拖放功能,那么您至少可以链接到文档。