将多部分表单发布到自身无法获取文件名

时间:2014-01-21 00:04:59

标签: jquery forms post file-upload

我正在使用jquery向自己发布一个表单,其中包含文件上传。我无法获取文件名,我一直没有设置userfile ...尝试捕获文件名时

$(document).ready(function(){
$("#chmail").validate({
debug: false,
submitHandler: function(form) {
$.post('new_mail.php', $("#chmail").serialize(), function(data) {
$('#mainBody').html(data);
$("#mainBody").find("script").each(function(i) {
eval($(this).text());
});
});
}
});
});

if (isset($_FILES["userfile"]["name"])) {
echo $_FILES["userfile"]["name"];
}


<form method="post" action="" id="chmail" name="chmail" enctype="multipart/form-data">
<input type="file" id="userfile" name="userfile" />
<button type="submit" value="Send">
</form>

任何帮助将不胜感激:) 非常感谢

1 个答案:

答案 0 :(得分:0)

这很好用

在页面上显示iframe。在表单中将目标设置为iframe,并设置操作以调用上载文件的脚本。不需要其他脚本

<iframe name="my-iframe" frameborder="0" scrolling="no"></iframe>


<form method="post" id="chmail" name="chmail" enctype="multipart/form-data" action="process_mail.php" target="my-iframe">