【发布时间】:2013-09-09 23:56:38
【问题描述】:
我想要做什么
我有一个通过ajaxForm 发布的表格。该表单包含一个file 输入字段,但数据并未与POST 中的其余信息一起处理。
代码
HTML 表单
<form id="profilepicForm" action="user/profilepic.php" method="post" enctype="multipart/form-data">
<input type="file" accept="image/gif, image/jpeg, image/png" name="file" />
<input type="hidden" name="userid" value="<?php echo $_SESSION['user']['id'] ?>" />
<input type="submit" value="Upload">
</form>
Javascript
var options = {
complete: function(response) {
$("#profilepicMessage").html(response.responseText);
},
error: function(){
$("#profilepicMessage").html("ERROR: unable to upload file");
}
};
$("#profilepicForm").ajaxForm(options);
PHP
$user_id = $_POST['userid'];
$image = $_FILES['file']['name'];
print_r($_POST);
exit;
发生了什么
所有通过的都是Array ( [userid] => 34 ),其中34 是我特定的userid。因此我知道表单 正在发布,但文件没有通过。
【问题讨论】:
-
见stackoverflow.com/questions/166221/… 你需要使用HTML5来做ajax文件上传。您正在使用可能不支持文件上传的 ajaxForm jQuery 插件。
-
如果你想做一个好的上传器,plupload 是一个很好的解决方案。值得一看。
-
look here插件页面给出了文件上传的例子
标签: php javascript ajax jquery ajaxform