Uploadify:使用scriptData将表单的ID作为参数传递 [英] Uploadify: Passing a form's ID as a parameter with scriptData

查看:105
本文介绍了Uploadify:使用scriptData将表单的ID作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够使用Uploadify在一页上(可能是数百个)上具有多个上传输入.上传的PHP文件将根据用于提交文件的输入按钮的ID重命名上传的文件,因此它将需要该ID.

I need the ability to have multiple upload inputs on one page (potentially hundreds) using Uploadify. The upload PHP file will be renaming the uploaded file based on the ID of the input button used to submit it, so it will need that ID.

由于我将在一页上有数百个上载按钮,因此我想创建一个通用实例化,因此我使用表单的类而不是表单的ID进行了此操作.但是,当单击其中一个输入时,我想将该输入的ID作为scriptData传递给PHP.这是行不通的. PHP说'formId'是未定义的.

Since I will be having hundreds of upload buttons on one page, I wanted to create a universal instantiation, so I did this using the class of the forms rather than the ID of the forms. However, when one of the inputs is clicked, I would like to pass the ID of that input as scriptData to the PHP. This is not working; PHP says 'formId' is undefined.

是否有一种好方法来获取正在使用的表单输入的ID属性,并将其传递给上载PHP?还是有一种完全不同且更好的方法来实现这一目标?预先谢谢你!

Is there a good way get the ID attribute of the form input being used, and passing it to the upload PHP? Or is there a completely different and better method of accomplishing this? Thank you in advance!!

  <script type="text/javascript">
    $(document).ready(function() {
      $('.uploady').uploadify({
        'uploader'  : '/uploadify/uploadify.swf',
        'script'    : '/uploadify/uploadify.php',
        'cancelImg' : '/uploadify/cancel.png',
        'folder'    : '/uploadify',
        'auto'      : true,
      // LINE IN QUESTION
      'scriptData'  : {'formId':$(this).attr('id')}
  });
});
</script>
</head>

输入看起来像这样:

<input id="file_upload1" class="uploady" name="file_upload" type="file" />
<input id="file_upload2" class="uploady" name="file_upload" type="file" />
<input id="file_upload3" class="uploady" name="file_upload" type="file" />

推荐答案

好一分钟前,我还在同一个问题上苦苦挣扎,这是解决方案,您可以在onSelect事件中定义元素时获取元素的ID.像下面一样

well I was struggling with the same issue just a minute ago and here is the solution, you can get the ID of the element as defining a function in onSelect event like below

//EDIT 这是工作代码

$('.uploady').uploadify({
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploadify',
    'auto'      : true,
    // ANSWER
    'onSelect'    : function(event,ID,fileObj) {
        var elem_id = $(event.target).attr("id"); //here you get the id of the object.
        $("#"+elem_id).uploadifySettings('scriptData',{'formID':elem_id})
    },
});

现在您的formID将被正确发送

now your formID would be sent correctly

这篇关于Uploadify:使用scriptData将表单的ID作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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