通过PHP jQuery的AJAX文件上传
我有一个问题,我的PHP文件上传通过AJAX jQuery中使用该即时通讯。
i have a problem with my php fileupload which im using via ajax in jquery.
这是我的code在PHP上传文件:
This is my code in the php upload file:
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],"termine.csv");
echo "Stored in: " . $_FILES["file"]["name"];
}
这是我的jQuery阿贾克斯语句:
This is my jquery ajax statement:
$('#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文件格式:
and this is my form in the index.php file:
<form enctype="multipart/form-data" id="csv" method="POST">
<div style="float:left">
<input name="file" type="file" id="file" size="100">
<br/>
<input type="submit" id="upload_csv" value="upload csv file">
</div>
</form>
唯一的错误消息我得到的是错误,并没有别的。
The only error message i get is "error" and nothing else.
希望有人可以提供帮助。
Hope somebody can help.
$()。序列化
通常会创建一个 URL-CN codeD
字符串,而忽略文件输入。你必须使用另一种方法。请参阅: http://api.jquery.com/serialize/
$().serialize
always creates a url-encoded
string, and ignores file input. You have to use another approach. See: http://api.jquery.com/serialize/
一种选择是把形式隐藏 IFRAME
键,触发submit事件。
One option is to put the form in a hidden iframe
and trigger the submit event.
另外看看jQuery的文件上传插件: HTTP://blueimp.github。 COM / jQuery的,文件上传/
Also take a look at the jQuery File Upload plugin: http://blueimp.github.com/jQuery-File-Upload/