Jquery ajax fileupload通过php

我的php fileupload有问题,我在jquery中通过ajax使用它。

这是我在php上传文件中的代码:

if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"termine.csv"); echo "Stored in: " . $_FILES["file"]["name"]; }

这是我的jquery ajax声明:

  $('#upload_csv').click( function() { $.ajax({ url: '/playground/php/updatedates.php', type: 'POST', data: $('form#csv').serialize(), }).done(function(txt) { if(txt!='')alert(txt); }); }); 

这是我在index.php文件中的表单:

 

我得到的唯一错误消息是“错误”而没有别的。

希望有人可以提供帮助。

$().serialize始终创建一个url-encoded字符串,并忽略文件输入。 你必须使用另一种方法。 请参阅: http : //api.jquery.com/serialize/

一种选择是将表单放在隐藏的iframe并触发提交事件。

另请参阅jQuery文件上传插件: http : //blueimp.github.com/jQuery-File-Upload/