plupload - 使用上传的文件发送另一个请求参数 [英] plupload - send another request parameter with uploaded file

查看:31
本文介绍了plupload - 使用上传的文件发送另一个请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

plupload文件对象.如何将此 id 发送到上传脚本?上传脚本在 $_POST 中有 3 个变量 - 文件名、块编号和块总数.

plupload creates nice ids in file object. How this id can be sent to the upload script? The upload script has 3 variables in $_POST - file name, chunk number and total number of chunks.

如何在 plupload 的 POST 请求中添加另一个参数(在我的例子中是 file.id)?

推荐答案

第一步是为 BeforeUpload 事件添加一个处理程序.

The first step would be to add a handler to the BeforeUpload event.

然后,如果您使用的是 multipart,您可以更改上传器设置以动态设置不同的 multipart 参数:

Then, if you are using multipart, you can change the uploader settings to dynamically set different multipart params:

plupload_instance.bind('BeforeUpload', function (up, file) {
    up.settings.multipart_params = {fileid: file.id}
});

(警告:这个例子覆盖了任何和所有的 multipart_params,你可以通过设置 fileid 玩得更聪明)

(warning: this example overrides any and all multipart_params, you can play it smarter than that by just setting fileid)

如果您不使用多部分,您唯一的选择是将参数作为标头传递,或者手动将参数添加到每个文件的 URL(这两个选项也应该在 BeforeUpload 中完成).请注意,当不使用 multipart 时,plupload 会将 namechunk 参数添加到 URL after 您已经为上传器设置的任何 URL,例如每个文件,所以这是额外的参数所在.

if you are not using multipart, your only options would be to pass the argument as a header, or to manually add the param to the URL for each file (these 2 options should also be done within BeforeUpload). Note that when not using multipart, plupload will add the name and chunk params to the URL after any URL you already set for the uploader, for each file, so this is where extra params go.

这篇关于plupload - 使用上传的文件发送另一个请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆