php 如何使用 PLupload 发送附加数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9535462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send additional data using PLupload?
提问by eric.itzhak
I'm using pluploadto make an ajax file uploading. Now the plupload.Uploader class has many options but none are additional data.
我正在使用plupload进行 ajax 文件上传。现在 plupload.Uploader 类有很多选项,但没有一个是附加数据。
For Example :
例如 :
var uploader = new plupload.Uploader({
runtimes : 'gears,html5,flash,silverlight,browserplus',
browse_button : 'pickfiles',
container : 'contact_container',
max_file_size : '10mb',
url : 'upload.php',
flash_swf_url : '/plupload/js/plupload.flash.swf',
silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
resize : {width : 320, height : 240, quality : 90}
});
What i'm trying to achive is i have a folder in my server where all the uploads are being saved. I neeed inside the folder to create a sub-folder to each user that have uploaded files there. How can i add data like id of the user to the instance of plupload.Uploader? Or if i'll wrap a form inside the container div, will i be able to see it in the $_REQUEST? Or is there some other way i can achive this?
我想要实现的是我的服务器中有一个文件夹,所有上传的内容都保存在其中。我需要在文件夹内为每个上传文件的用户创建一个子文件夹。如何将用户 ID 等数据添加到 plupload.Uploader 实例中?或者,如果我将一个表单包装在容器 div 中,我能在 $_REQUEST 中看到它吗?或者还有其他方法可以实现吗?
回答by elconejito
Have you tried using the setting for multipart_params? Add an additional option to your plupload.Uploader like so:
您是否尝试过使用 multipart_params 的设置?向您的 plupload.Uploader 添加一个附加选项,如下所示:
var uploader = new plupload.Uploader({
runtimes : 'gears,html5,flash,silverlight,browserplus',
browse_button : 'pickfiles',
container : 'contact_container',
max_file_size : '10mb',
url : 'upload.php',
flash_swf_url : '/plupload/js/plupload.flash.swf',
silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
resize : {width : 320, height : 240, quality : 90},
multipart_params : {
"name1" : "value1",
"name2" : "value2"
}
});
You will then need to process the values in the file that handles the upload (upload.php by default). I think the values are captured by $_POST
but you can use $_REQUEST
just to be sure.
然后,您需要处理处理上传的文件中的值(默认情况下为upload.php)。我认为这些值是由捕获的,$_POST
但您可以使用$_REQUEST
它来确定。
I've used jQuery to assign values on the fly, so instead of "name1" : "value1"
you can use something like "name1" : $("#name1").val(),
where #name1 might be an input elsewhere on the page.
我已经使用 jQuery 即时分配值,因此"name1" : "value1"
您可以使用诸如"name1" : $("#name1").val(),
#name1 可能是页面上其他地方的输入之类的东西。
Plupload's documentation is a little sparse for some of these settings.
对于其中一些设置,Plupload 的文档有点稀少。
回答by pb ty
You can use uploader.settings.multipart_params["name1"] = yourValue;
but "name1"
must be declared in uploader config :
您可以使用uploader.settings.multipart_params["name1"] = yourValue;
但"name1"
必须在上传器配置中声明:
multipart_params : {
"name1" : "value1",
"name2" : "value2"
}
回答by Agu Dondo
If you need to dynamically add parameters on every file upload you can do this:
如果您需要在每个文件上传时动态添加参数,您可以这样做:
uploader.bind('BeforeUpload', function(up, file) {
up.settings.multipart_params = {
"parameter1": "value1",
"paremeter2": "value2"
};
});
回答by Briscoe
You can also use
你也可以使用
uploader.settings.url = "upload.php?param1=whatever"
and just pass it as a get variable.
并将其作为 get 变量传递。