我相信您可以使用Uploadify做到这一点。您需要查看两个选项。首先,将auto 设置为 false以防止立即加载选定的文件。其次,使用formdata 选项将您的其他表单字段与有效负载一起发送。
然后,当用户提交表单时,您将调用upload 方法,上传队列中的每个文件并一次发送所有表单数据。
服务器端部分:
您可能会将表单提交给 ASPX 文件或 ASHX 处理程序。我更喜欢使用 ASHX 处理程序,因为它们更轻。两者都将允许您访问HttpContext
或HttpRequest
对象。首先,您需要检查context.Request.Files.Count
以确保文件已发布:
if (context.Request.Files.Count > 0) // We have files uploaded
{
var file = context.Request.Files[0]; // First file, but there could be others
// You can call file.SaveAs() to save the file, or file.InputString to access a stream
}
获取其他表单字段应该同样简单:
var formfield = context.Request["MyFormField"]; // Some form field
您还可以将结果写回客户端,例如任何结果错误的 JSON 编码描述:
context.Response.Write(response); // Anything you write here gets passed in to onUploadSuccess
我认为这应该让你开始吧!